TeamNewPipe/NewPipe · error · EOFException

EOF reached in box: type=%s offset=%s size=%s

Error message

EOF reached in box: type=%s offset=%s size=%s

What it means

Mp4DashReader.readFullBox allocates a ByteBuffer for the declared box size and reads (size - 8) bytes after the 8-byte header. If stream.read returns fewer bytes than requested, the box content is incomplete and an EOFException with type/offset/size is thrown. It guards against a box header claiming a size larger than what the stream can deliver.

Source

Thrown at app/src/main/java/org/schabi/newpipe/streams/Mp4DashReader.java:298

        if (b.type != expected) {
            throw new NoSuchElementException("expected " + boxName(expected)
                    + " found " + boxName(b));
        }
        return b;
    }

    private byte[] readFullBox(final Box ref) throws IOException {
        // full box reading is limited to 2 GiB, and should be enough
        final int size = (int) ref.size;

        final ByteBuffer buffer = ByteBuffer.allocate(size);
        buffer.putInt(size);
        buffer.putInt(ref.type);

        final int read = size - 8;

        if (stream.read(buffer.array(), 8, read) != read) {
            throw new EOFException(String.format("EOF reached in box: type=%s offset=%s size=%s",
                    boxName(ref.type), ref.offset, ref.size));
        }

        return buffer.array();
    }

    private void ensure(final Box ref) throws IOException {
        final long skip = ref.offset + ref.size - stream.position();

        if (skip == 0) {
            return;
        } else if (skip < 0) {
            throw new EOFException(String.format(
                    "parser go beyond limits of the box. type=%s offset=%s size=%s position=%s",
                    boxName(ref), ref.offset, ref.size, stream.position()
            ));
        }

View on GitHub (pinned to 9e8be09156)

Solutions

  1. Re-download the file; the box body is incomplete.
  2. Validate the file's total length against the sum of declared box sizes before parsing deep structures.
  3. Check the download completed (HTTP 200, full Content-Length received) before demuxing.
  4. Catch EOFException and surface a 'media incomplete' error to the user.

Example fix

// no caller-side fix for a truncated box; guard at the download boundary
// before
SharpStream s = download(url); // may be truncated
reader.parse();

// after — assert full download before parsing
if (downloadedBytes != response.contentLength()) {
    throw new IOException("incomplete download");
}
reader.parse();
Defensive patterns

Strategy: validation

Validate before calling

// Verify the stream length covers the largest declared box size before deep parsing.
if (source.isLengthKnown() && source.length() < firstBoxSize) {
    throw new IOException("source shorter than declared first box size");
}

Type guard

// Wrap the stream to fail fast on short reads at the box boundary.
public static boolean canReadFullBox(SharpStream s, long boxSize) {
    return s.isLengthKnown() && (s.length() - s.position()) >= boxSize;
}

Try / catch

try {
    byte[] body = readFullBox(boxRef);
} catch (EOFException e) {
    // box body truncated — file is incomplete, do not retry
    throw new IOException("incomplete MP4 box at offset " + boxRef.offset, e);
}

Prevention

When it happens

Trigger: Reading any full box (mvhd, tkhd, tfhd, trun, etc.) whose declared size exceeds the remaining bytes in the stream. The header was read successfully but the body was truncated.

Common situations: A download cut off mid-box; a box size field corrupted to an inflated value; a server that closed the connection after sending headers; a cached file partially written.

Related errors


AI-assisted analysis of TeamNewPipe/NewPipe@9e8be09156 (2026-08-14). Data as JSON: /api/errors/3e30ac874658dca0. Report an issue: GitHub.