{"record":{"id":"da5f207eccc17800","repo":"nilaoda/N_m3u8DL-RE","slug":"the-samples-do-not-fit-evenly-into-the-sample-sizes-given-in","errorCode":null,"errorMessage":"The samples do not fit evenly into the sample sizes given in the TRUN box!","messagePattern":"The samples do not fit evenly into the sample sizes given in the TRUN box!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/N_m3u8DL-RE.Parser/Mp4/MP4VttUtil.cs","lineNumber":168,"sourceCode":"                                if (index != -1)\n                                {\n                                    cues[index].EndTime = cue.EndTime;\n                                }\n                                else\n                                {\n                                    cues.Add(cue);\n                                }\n                            }\n                        }\n                    }\n                    else\n                    {\n                        throw new Exception(\"WVTT sample duration unknown, and no default found!\");\n                    }\n\n                    if (!(presentation.SampleSize == 0 || totalSize <= presentation.SampleSize))\n                    {\n                        throw new Exception(\"The samples do not fit evenly into the sample sizes given in the TRUN box!\");\n                    }\n\n                } while (presentation.SampleSize != 0 && (totalSize < presentation.SampleSize));\n\n                if (reader.HasMoreData())\n                {\n                    // throw new Exception(\"MDAT which contain VTT cues and non-VTT data are not currently supported!\");\n                }\n            }\n        }\n\n        if (cues.Count > 0)\n        {\n            return new WebVttSub() { Cues = cues };\n        }\n        return new WebVttSub();\n    }\n","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/nilaoda/N_m3u8DL-RE/blob/e113dee70c924ee08dae5460624909b04d84cb76/src/N_m3u8DL-RE.Parser/Mp4/MP4VttUtil.cs#L150-L186","documentation":"After reading a WVTT sample from the mdat payload, ExtractSub checks that the consumed bytes (totalSize) fit within the sample size declared in the TRUN box (presentation.SampleSize). If the sample data exceeds the declared size, the trun sample table and the actual payload disagree, and cue boundaries would be misaligned, so it throws.","triggerScenarios":"The mdat payload contains more bytes than the sum of trun-declared sample sizes — e.g. segment was produced/re-muxed with inconsistent trun sample_size values, or the wrong trun was paired with this mdat.","commonSituations":"Corrupt or hand-edited fragments; mixing segments from different init media; packager bugs where sample sizes don't match the emitted payload.","solutions":["Re-download/re-mux the segment so trun sample_size values match the actual payload.","Ensure the correct init segment matches the media segment (same track/sequence).","Validate the fragment with an MP4 inspector to compare trun sample sizes vs mdat length.","Patch parsing to tolerate overflow by clamping to SampleSize if the extra bytes are padding."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// compare trun-declared total sample size to mdat length before parsing\n// if mismatch, re-fetch or re-mux the fragment instead of parsing","typeGuard":null,"tryCatchPattern":"try { var subs = MP4VttUtil.ExtractSub(dataSeg, baseTime); }\ncatch (Exception ex) when (ex.Message.Contains(\"do not fit evenly\")) {\n    logger.Warn(\"trun/mdat size mismatch, re-downloading segment\");\n    dataSeg = await reDownloadAsync(segmentUrl);\n}","preventionTips":["Always pair media segments with their matching init segment.","Validate fragments with mp4dump/mp4info in CI for new sources.","Avoid mixing segments from different streams/sequences.","Re-mux with a standard packager if sample sizes are inconsistent."],"tags":["mp4","subtitles","corrupt-segment"],"backgroundTag":"schema-validation-failed","analyzedSha":"e113dee70c924ee08dae5460624909b04d84cb76","analyzedAt":"2026-09-13T02:43:21.078Z","contentChangedAt":"2026-09-13T02:43:21.078Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}