remotion-dev/remotion · error · Error
Expected box size of ${bytesRemaining}, got ${boxSize}
Error message
Expected box size of ${bytesRemaining}, got ${boxSize} What it means
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.
Source
Thrown at packages/media-parser/src/containers/iso-base-media/stsd/samples.ts:140
'ac-3',
'Opus',
];
export const processIsoFormatBox = async ({
iterator,
logLevel,
contentLength,
}: {
iterator: BufferIterator;
logLevel: MediaParserLogLevel;
contentLength: number;
}): Promise<FormatBoxAndNext> => {
const fileOffset = iterator.counter.getOffset();
const bytesRemaining = iterator.bytesRemaining();
const boxSize = iterator.getUint32();
if (bytesRemaining < boxSize) {
throw new Error(`Expected box size of ${bytesRemaining}, got ${boxSize}`);
}
const boxFormat = iterator.getAtom();
const isVideo = videoTags.includes(boxFormat);
const isAudio =
audioTags.includes(boxFormat) || audioTags.includes(Number(boxFormat));
// 6 reserved bytes
iterator.discard(6);
const dataReferenceIndex = iterator.getUint16();
if (!isVideo && !isAudio) {
const bytesRemainingInBox =
boxSize - (iterator.counter.getOffset() - fileOffset);
iterator.discard(bytesRemainingInBox);
View on GitHub (pinned to 78fe4bb3fd)
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.
Example fix
// before: parsing a partial buffer where declared size > remaining bytes // after: wait until the full box is buffered const fullBoxReady = iterator.bytesRemaining() >= declaredBoxSize; if (!fullBoxReady) return needMoreData();
Defensive patterns
Strategy: validation
Validate before calling
// Ensure the full box is buffered before parsing sample entries
const remaining = iterator.bytesRemaining();
if (remaining < declaredBoxSize) {
// need more data; do not call parseIsoFormatBox yet
} Try / catch
try {
await parseMedia({src, fields: {dimensions: true}});
} catch (err) {
if (err instanceof Error && err.message.startsWith('Expected box size of')) {
// file truncated; fetch complete bytes or reject the upload
} else throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- read too many bytes - size: ${size}, read: ${iterator.counte
- Expected remaining bytes to be 0, got ${remaining}
- expected 0 bytes ${bytesRemaining}
- Expected stsz box in trak box
- Expected stco box in trak box
AI-assisted analysis of remotion-dev/remotion@78fe4bb3fd (2026-08-12).
Data as JSON: /api/errors/6c30b42e6a1acf21.
Report an issue: GitHub.