{"record":{"id":"681389be9edeca27","repo":"TeamNewPipe/NewPipe","slug":"fragment-element-not-found","errorCode":null,"errorMessage":"Fragment element not found","messagePattern":"Fragment element not found","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"app/src/main/java/org/schabi/newpipe/streams/WebMReader.java","lineNumber":72,"sourceCode":"    private WebMTrack[] tracks;\n    private int selectedTrack;\n    private boolean done;\n    private boolean firstSegment;\n\n    public WebMReader(final SharpStream source) {\n        this.stream = new DataReader(source);\n    }\n\n    public void parse() throws IOException {\n        Element elem = readElement(ID_EMBL);\n        if (!readEbml(elem, 1, 2)) {\n            throw new UnsupportedOperationException(\"Unsupported EBML data (WebM)\");\n        }\n        ensure(elem);\n\n        elem = untilElement(null, ID_SEGMENT);\n        if (elem == null) {\n            throw new IOException(\"Fragment element not found\");\n        }\n        segment = readSegment(elem, 0, true);\n        tracks = segment.tracks;\n        selectedTrack = -1;\n        done = false;\n        firstSegment = true;\n    }\n\n    public WebMTrack[] getAvailableTracks() {\n        return tracks;\n    }\n\n    public WebMTrack selectTrack(final int index) {\n        selectedTrack = index;\n        return tracks[index];\n    }\n\n    public Segment getNextSegment() throws IOException {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/TeamNewPipe/NewPipe/blob/9e8be091560a69f35d44bd252eb00bc7911c977b/app/src/main/java/org/schabi/newpipe/streams/WebMReader.java#L54-L90","documentation":"WebMReader.parse() reads the EBML header, then calls untilElement(null, ID_SEGMENT) to find the top-level Segment element. If no Segment is found before the stream ends, it returns null and parse() throws IOException 'Fragment element not found'. Every valid WebM must contain a Segment; its absence means the file is truncated or not WebM.","triggerScenarios":"Parsing a byte stream that has an EBML header but no Segment element — e.g. only the EBML header was downloaded, the Segment was cut off, or the data after the header is not a WebM Segment.","commonSituations":"A download that captured only the header/init bytes; a corrupted or partial file; a non-WebM file that coincidentally has a valid EBML header; a stream closed after the header.","solutions":["Re-download the full WebM file; the Segment payload is missing.","Verify the source is actually a WebM/Matroska file and not just an EBML header.","Check the download completed (full Content-Length) before parsing.","Confirm range requests include the Segment region, not just the header."],"exampleFix":"// no in-process fix for a missing Segment; validate the download\n// before\nnew WebMReader(partialStream).parse(); // IOException: no Segment\n\n// after — ensure the full file is present\nif (downloadedLength < headerSize + minSegmentSize) {\n    throw new IOException(\"download truncated before WebM segment\");\n}\nnew WebMReader(fullStream).parse();","handlingStrategy":"validation","validationCode":"// Confirm the file is long enough to contain an EBML header + Segment, and is WebM.\nbyte[] magic = new byte[4];\nsource.read(magic);\nif ((magic[0]&0xFF)!=0x1A||(magic[1]&0xFF)!=0x45||(magic[2]&0xFF)!=0xDF||(magic[3]&0xFF)!=0xA3) {\n    throw new IOException(\"not a WebM/Matroska file (bad EBML magic)\");\n}","typeGuard":"public static boolean hasEbmlMagic(byte[] head) {\n    return head != null && head.length >= 4\n        && (head[0]&0xFF)==0x1A && (head[1]&0xFF)==0x45\n        && (head[2]&0xFF)==0xDF && (head[3]&0xFF)==0xA3;\n}","tryCatchPattern":"try {\n    reader.parse();\n} catch (IOException e) {\n    if (e.getMessage().contains(\"Fragment element not found\")) {\n        // header present but Segment missing — re-download the full file\n        redownloadFullStream();\n    } else throw e;\n}","preventionTips":["Verify the EBML magic (0x1A45DFA3) before parsing.","Ensure downloads complete fully before parsing.","Confirm range requests include the Segment region.","Validate file length against expected WebM minimum size."],"tags":["webm","truncated-data","container","io","java"],"backgroundTag":null,"analyzedSha":"9e8be091560a69f35d44bd252eb00bc7911c977b","analyzedAt":"2026-08-14T00:11:33.519Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}