{"record":{"id":"b29a0904f6c43612","repo":"remotion-dev/remotion","slug":"invalid-xing-header","errorCode":null,"errorMessage":"Invalid Xing header","messagePattern":"Invalid Xing header","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/media-parser/src/containers/mp3/parse-xing.ts","lineNumber":53,"sourceCode":"\n\tif (h_id) {\n\t\t// mpeg1\n\t\tif (h_mode !== 3) {\n\t\t\txingOffset += 32 + 4;\n\t\t} else {\n\t\t\txingOffset += 17 + 4;\n\t\t}\n\t} else if (h_mode !== 3) {\n\t\txingOffset += 17 + 4;\n\t} else {\n\t\txingOffset += 9 + 4;\n\t}\n\n\tconst expectXing = new TextDecoder('utf8').decode(\n\t\tdata.slice(xingOffset, xingOffset + 4),\n\t);\n\tif (expectXing !== 'Xing') {\n\t\tthrow new Error('Invalid Xing header');\n\t}\n\n\tlet sampleRate = SAMPLE_RATES[h_sr_index];\n\tif (h_id === 0) {\n\t\tsampleRate >>= 1;\n\t}\n\n\tlet offset = xingOffset + 4;\n\n\tconst flags = extractI4(data, offset);\n\toffset += 4;\n\n\tlet numberOfFrames;\n\tlet fileSize;\n\tlet tableOfContents;\n\tlet vbrScale;\n\n\tif (flags & FRAMES_FLAG) {","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/media-parser/src/containers/mp3/parse-xing.ts#L35-L71","documentation":"Thrown by parseXing() when the 4 ASCII bytes at the computed xingOffset do not equal 'Xing'. The offset is derived from the MPEG version and mode bits in the first frame header, so a mismatch means either the frame is not a VBR info frame or the header bits led the parser to the wrong location. This is the parser asserting it was promised a Xing/VBR header but did not find one.","triggerScenarios":"parseXing() is invoked on a buffer that is not actually a Xing-tagged frame: CBR MP3s (no Xing tag), a frame whose side-info length differs from the computed offset, or a buffer that starts mid-stream. Also triggered if the caller assumes VBR but the file is CBR.","commonSituations":"Passing a CBR-encoded MP3 into a VBR code path; truncated first frame; MP3 produced by an encoder that writes 'Info' instead of 'Xing' (the parser only matches 'Xing'); mis-detected container.","solutions":["Confirm the file actually has a Xing tag (ffmpeg -i file.mp3 will show '.Container: ...' / Xing metadata); if it is CBR, use the CBR seek path instead of VBR.","If the tag says 'Info' (CBR files use 'Info' marker), re-encode with a VBR encoder so a real 'Xing' tag is written: ffmpeg -i in.mp3 -c:a libmp3lame -q:a 2 out.mp3","Guard parseXing() calls with a try/catch and fall back to CBR seek logic when it throws."],"exampleFix":"// before\nconst xing = parseXing(firstFrameBytes);\n\n// after\nlet xing: XingData | null = null;\ntry {\n  xing = parseXing(firstFrameBytes);\n} catch {\n  // not a VBR file; fall back to CBR seek\n  xing = null;\n}","handlingStrategy":"try-catch","validationCode":"// Pre-check the 4 bytes at the expected Xing offset before calling parseXing.\nfunction hasXingTag(firstFrame: Uint8Array): boolean {\n  const h_id = (firstFrame[1] >> 3) & 1;\n  const h_mode = (firstFrame[3] >> 6) & 3;\n  let off = 0;\n  if (h_id) off = h_mode !== 3 ? 32 + 4 : 17 + 4;\n  else off = h_mode !== 3 ? 17 + 4 : 9 + 4;\n  return (\n    firstFrame.length >= off + 4 &&\n    new TextDecoder().decode(firstFrame.subarray(off, off + 4)) === 'Xing'\n  );\n}","typeGuard":"null","tryCatchPattern":"let xing: XingData | null;\ntry {\n  xing = parseXing(firstFrame);\n} catch {\n  xing = null; // not a VBR/Xing frame; use CBR path\n}","preventionTips":["Use the VBR/Xing path only after confirming a 'Xing' marker is present.","Remember CBR MP3s use the 'Info' marker, which parseXing does not accept.","Fall back to CBR seek when parseXing throws."],"tags":["mp3","xing","vbr","media-parser"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}