{"record":{"id":"6c30b42e6a1acf21","repo":"remotion-dev/remotion","slug":"expected-box-size-of-bytesremaining-got-boxs-6c30b4","errorCode":null,"errorMessage":"Expected box size of ${bytesRemaining}, got ${boxSize}","messagePattern":"Expected box size of (.+?), got (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/iso-base-media/stsd/samples.ts","lineNumber":140,"sourceCode":"\t'ac-3',\n\t'Opus',\n];\n\nexport const processIsoFormatBox = async ({\n\titerator,\n\tlogLevel,\n\tcontentLength,\n}: {\n\titerator: BufferIterator;\n\tlogLevel: MediaParserLogLevel;\n\tcontentLength: number;\n}): Promise<FormatBoxAndNext> => {\n\tconst fileOffset = iterator.counter.getOffset();\n\tconst bytesRemaining = iterator.bytesRemaining();\n\tconst boxSize = iterator.getUint32();\n\n\tif (bytesRemaining < boxSize) {\n\t\tthrow new Error(`Expected box size of ${bytesRemaining}, got ${boxSize}`);\n\t}\n\n\tconst boxFormat = iterator.getAtom();\n\n\tconst isVideo = videoTags.includes(boxFormat);\n\tconst isAudio =\n\t\taudioTags.includes(boxFormat) || audioTags.includes(Number(boxFormat));\n\n\t// 6 reserved bytes\n\titerator.discard(6);\n\n\tconst dataReferenceIndex = iterator.getUint16();\n\n\tif (!isVideo && !isAudio) {\n\t\tconst bytesRemainingInBox =\n\t\t\tboxSize - (iterator.counter.getOffset() - fileOffset);\n\t\titerator.discard(bytesRemainingInBox);\n","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/iso-base-media/stsd/samples.ts#L122-L158","documentation":"Thrown when a sample-entry box declares a size larger than the bytes remaining in the buffer. The parser reads boxSize via getUint32 and compares to iterator.bytesRemaining(); a boxSize greater than what is left indicates truncation, corruption, or a parser that has already over-consumed earlier bytes.","triggerScenarios":"Calling parseIsoFormatBox on a truncated stream where the declared atom size exceeds available data, or after an earlier parser left the cursor past the true box boundary.","commonSituations":"Streaming/incomplete downloads where the moov or mdat is cut off; files served with an incorrect Content-Length; partial writes from a recorder that crashed mid-encode.","solutions":["Confirm the file is fully downloaded: compare file size on disk to the Content-Length / expected size.","Run `mp4box -info input.mp4` or `ffprobe` to locate the corrupt atom.","Re-fetch or re-encode the source so the byte stream is complete.","If parsing a stream incrementally, ensure you have buffered the full box (size + 8 header) before invoking parseIsoFormatBox."],"exampleFix":"// before: parsing a partial buffer where declared size > remaining bytes\n// after: wait until the full box is buffered\nconst fullBoxReady = iterator.bytesRemaining() >= declaredBoxSize;\nif (!fullBoxReady) return needMoreData();","handlingStrategy":"validation","validationCode":"// Ensure the full box is buffered before parsing sample entries\nconst remaining = iterator.bytesRemaining();\nif (remaining < declaredBoxSize) {\n  // need more data; do not call parseIsoFormatBox yet\n}","typeGuard":null,"tryCatchPattern":"try {\n  await parseMedia({src, fields: {dimensions: true}});\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Expected box size of')) {\n    // file truncated; fetch complete bytes or reject the upload\n  } else throw err;\n}","preventionTips":["Verify Content-Length matches actual bytes received before parsing.","For streaming, buffer the full declared box (size + 8) before invoking the parser.","Use ffprobe to confirm file integrity before programmatic parsing."],"tags":["media-parser","isobmiff","truncated-file","box-size","mp4"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}