{"record":{"id":"296a47f48dd9e3cf","repo":"remotion-dev/remotion","slug":"xing-header-was-parsed-wrong-read-beyond-availabl","errorCode":null,"errorMessage":"xing header was parsed wrong: read beyond available data","messagePattern":"xing header was parsed wrong: read beyond available data","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/mp3/parse-xing.ts","lineNumber":93,"sourceCode":"\n\tif (flags & BYTES_FLAG) {\n\t\tfileSize = extractI4(data, offset);\n\t\toffset += 4;\n\t}\n\n\tif (flags & TOC_FLAG) {\n\t\ttableOfContents = data.slice(offset, offset + 100);\n\t\toffset += 100;\n\t}\n\n\tif (flags & VBR_SCALE_FLAG) {\n\t\tvbrScale = extractI4(data, offset);\n\t\toffset += 4;\n\t}\n\n\t// Allow extra data after the standard Xing fields, as some encoders add additional information\n\tif (offset > data.length) {\n\t\tthrow new Error('xing header was parsed wrong: read beyond available data');\n\t}\n\n\treturn {\n\t\tsampleRate,\n\t\tnumberOfFrames: numberOfFrames ?? null,\n\t\tfileSize: fileSize ?? null,\n\t\ttableOfContents: tableOfContents\n\t\t\t? Array.from(tableOfContents.slice(0, 100))\n\t\t\t: null,\n\t\tvbrScale: vbrScale ?? null,\n\t};\n};\n\nexport const getSeekPointInBytes = ({\n\tfileSize,\n\tpercentBetween0And100,\n\ttableOfContents,\n}: {","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/mp3/parse-xing.ts#L75-L111","documentation":"Thrown by parseXing() after consuming the flag-driven fields (numberOfFrames, fileSize, 100-byte TOC, vbrScale) when the running offset has moved past data.length. The comment above the check says extra trailing data is allowed, so the throw fires only when the standard fields themselves overran the buffer — i.e. the flags word claimed fields the buffer could not satisfy.","triggerScenarios":"A Xing header whose flags word is corrupt or whose TOC/fields are truncated (e.g. flags say TOC_FLAG is set but the buffer has fewer than 100 bytes remaining after numberOfFrames/fileSize). Also possible if a wrong xingOffset caused the flags to be read from the wrong position, yielding bogus large flags.","commonSituations":"Truncated first MP3 frame (e.g. only partial bytes fetched from a network range request); a malformed Xing tag from a buggy encoder; bit-flips in the flags word.","solutions":["Ensure the full first MP3 frame (typically ~417+ bytes for MPEG1) is buffered before calling parseXing() — fetch a larger byte range or read the whole frame.","Re-encode the file so a clean Xing tag is written: ffmpeg -i in.mp3 -c:a libmp3lame -q:a 2 out.mp3","Wrap parseXing() in try/catch and fall back to CBR seek when it fails."],"exampleFix":"// before\nconst xing = parseXing(partialBuffer);\n\n// after: pass a buffer large enough for the whole first frame\nconst FRAME_SIZE = mpegVersion === 1 ? 417 : 209;\nconst xing = parseXing(firstFrame.subarray(0, FRAME_SIZE));","handlingStrategy":"validation","validationCode":"// Ensure the first frame buffer is large enough to hold all Xing fields (worst case ~417 bytes for MPEG-1).\nconst MIN_XING_BUF = 417;\nif (firstFrame.length < MIN_XING_BUF) {\n  // fetch more bytes / wait for the full frame before calling parseXing\n}","typeGuard":"null","tryCatchPattern":"try {\n  const xing = parseXing(firstFrame);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('xing header was parsed wrong')) {\n    // buffer truncated: re-fetch full first frame and retry, or fall back to CBR\n  } else throw err;\n}","preventionTips":["Buffer the entire first MP3 frame before parsing the Xing header.","For network sources, request a byte range large enough to cover the first frame plus side info.","Re-encode suspect files to regenerate a clean Xing tag."],"tags":["mp3","xing","vbr","truncated-data","media-parser"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}