TeamNewPipe/NewPipe · error · IOException

Unexpected SimpleBlock element size, missing %s bytes

Error message

Unexpected SimpleBlock element size, missing %s bytes

What it means

Thrown while reading a SimpleBlock inside a WebM Cluster. After consuming the block header (variable-length track number = readEncodedNumber(), a 2-byte relativeTimeCode via readShort(), and a 1-byte flags field), the reader computes dataSize as (ref.offset + ref.size) - stream.position(). If that value is negative it means the three header fields consumed more bytes than the SimpleBlock element actually contains — the element's declared size is inconsistent with the stream contents. This is a structural integrity check: a block must have room for at least its header plus payload.

Source

Thrown at app/src/main/java/org/schabi/newpipe/streams/WebMReader.java:380

                    entry.kind = TrackKind.Other;
                    break;
            }
        }

        return entries;
    }

    private SimpleBlock readSimpleBlock(final Element ref) throws IOException {
        final SimpleBlock obj = new SimpleBlock(ref);
        obj.trackNumber = readEncodedNumber();
        obj.relativeTimeCode = stream.readShort();
        obj.flags = (byte) stream.read();
        obj.dataSize = (int) ((ref.offset + ref.size) - stream.position());
        obj.createdFromBlock = ref.type == ID_BLOCK;

        // NOTE: lacing is not implemented, and will be mixed with the stream data
        if (obj.dataSize < 0) {
            throw new IOException(String.format(
                    "Unexpected SimpleBlock element size, missing %s bytes", -obj.dataSize));
        }
        return obj;
    }

    private Cluster readCluster(final Element ref) throws IOException {
        final Cluster obj = new Cluster(ref);

        final Element elem = untilElement(ref, ID_TIMECODE);
        if (elem == null) {
            throw new NoSuchElementException("Cluster at " + ref.offset
                    + " without Timecode element");
        }
        obj.timecode = readNumber(elem);

        return obj;
    }

View on GitHub (pinned to 9e8be09156)

Solutions

  1. Verify the file is not truncated: compare its length against the expected Content-Length or the WebM Segment size element.
  2. Re-download the media: a negative dataSize almost always means the file bytes are damaged or incomplete.
  3. Catch IOException at the demux call site and treat the file as corrupt rather than retrying in-place.
  4. If this occurs during live streaming, check that the byte-range request that fetched this Cluster returned the correct, complete range.
Defensive patterns

Strategy: validation

Validate before calling

// Before reading SimpleBlocks, sanity-check the element content size
// is at least large enough for the header (trackNum + 2 + 1 = 4 bytes min):
long minHeader = 4; // conservative lower bound for encoded track number + short + byte
if (ref.contentSize < minHeader) {
    throw new IOException("SimpleBlock element too small at offset " + ref.offset);
}

Try / catch

try {
    SimpleBlock block = readSimpleBlock(elem);
} catch (IOException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Unexpected SimpleBlock element size")) {
        // stream is corrupt or truncated — abort demux of this cluster
        Log.w(TAG, "Corrupt SimpleBlock, skipping cluster", e);
    } else throw e;
}

Prevention

When it happens

Trigger: readSimpleBlock() is called on an Element whose contentSize/size is smaller than the sum of the encoded track number length + 2 (short) + 1 (byte). Occurs when the EBML element size field is wrong, the stream is truncated mid-block, or the reader is misaligned due to a preceding parse error.

Common situations: Truncated download (file cut off inside a Block); byte-level corruption of the WebM container changing an element size field; seek/demux logic that advanced the stream pointer to the wrong offset; a malformed server response or proxy that altered byte ranges.

Related errors


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