{"record":{"id":"b792d0c39fec0854","repo":"TeamNewPipe/NewPipe","slug":"parser-go-beyond-limits-of-the-element-type-s-of","errorCode":null,"errorMessage":"parser go beyond limits of the Element. type=%s offset=%s size=%s position=%s","messagePattern":"parser go beyond limits of the Element\\. type=(.+?) offset=(.+?) size=(.+?) position=(.+?)","errorType":"exception","errorClass":"EOFException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/schabi/newpipe/streams/WebMReader.java","lineNumber":219,"sourceCode":"            }\n\n            ensure(elem);\n        }\n\n        return null;\n    }\n\n    private String elementID(final long type) {\n        return \"0x\".concat(Long.toHexString(type));\n    }\n\n    private void ensure(final Element ref) throws IOException {\n        final long skip = (ref.offset + ref.size) - stream.position();\n\n        if (skip == 0) {\n            return;\n        } else if (skip < 0) {\n            throw new EOFException(String.format(\n                    \"parser go beyond limits of the Element. type=%s offset=%s size=%s position=%s\",\n                    elementID(ref.type), ref.offset, ref.size, stream.position()\n            ));\n        }\n\n        stream.skipBytes(skip);\n    }\n\n    private boolean readEbml(final Element ref, final int minReadVersion,\n                             final int minDocTypeVersion) throws IOException {\n        Element elem = untilElement(ref, ID_EMBL_READ_VERSION);\n        if (elem == null) {\n            return false;\n        }\n        if (readNumber(elem) > minReadVersion) {\n            return false;\n        }\n","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/TeamNewPipe/NewPipe/blob/9e8be091560a69f35d44bd252eb00bc7911c977b/app/src/main/java/org/schabi/newpipe/streams/WebMReader.java#L201-L237","documentation":"WebMReader.ensure(ref) computes how many bytes remain to the end of the current element (ref.offset + ref.size - stream.position()). A negative skip means the parser already read past the element's declared boundary — a sub-parser consumed more bytes than the element allows, indicating corrupt or inconsistent EBML sizes. EOFException reports type/offset/size/position.","triggerScenarios":"Any ensure(ref) call after parsing element children where the child content exceeded the parent element's declared content size. The parent's size is smaller than what its children occupy, or a child's length overran.","commonSituations":"A malformed WebM with an undersized element size relative to its content; a corrupted Block/Cluster whose length fields are inconsistent; a tampered file; a muxer bug producing inconsistent nested sizes.","solutions":["Re-download or re-mux; nested element sizes are internally inconsistent.","Validate with mkvinfo/ffprobe which reports structural inconsistencies.","If you produce the files, audit nested size computation so children never exceed parent extents.","Treat as fatal for the current cluster and skip forward to the next Cluster ID if resilience is needed."],"exampleFix":"// before — sub-parser overruns parent element and trips ensure()\nparseChildren(elem); // reads past elem.size\n\n// after — bound child reads by the parent element limit\nlong limit = elem.offset + elem.size;\nwhile (stream.position() < limit) { parseChild(elem); }","handlingStrategy":"validation","validationCode":"// Producer-side: ensure sub-parsers never read past the parent element boundary.\nlong parentEnd = elem.offset + elem.size;\nwhile (stream.position() < parentEnd) {\n    parseChild(elem, parentEnd); // pass limit, clamp child reads\n}","typeGuard":"public static boolean childWithinParent(long childEnd, long parentEnd) {\n    return childEnd <= parentEnd;\n}","tryCatchPattern":"try {\n    ensure(elem);\n} catch (EOFException e) {\n    if (e.getMessage().contains(\"beyond limits\")) {\n        // parser overran the element — skip forward to the next Cluster\n        Log.w(TAG, \"element overrun: \" + e.getMessage());\n        skipToNextCluster();\n    } else throw e;\n}","preventionTips":["Re-mux corrupt WebM files with a conformant tool.","Validate nested element sizes with mkvinfo/ffprobe.","When implementing sub-parsers, clamp reads to the parent element extent.","Treat overruns as fatal for the current cluster, not the whole file."],"tags":["webm","ebml","corrupt-data","offset-validation","java"],"backgroundTag":null,"analyzedSha":"9e8be091560a69f35d44bd252eb00bc7911c977b","analyzedAt":"2026-08-14T00:11:33.519Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}