Skip to content

🎥 Make videos programmatically with React

Fix Xing header parsing to allow extra data after standard fields

copilot-swe-agent[bot]6d481e57b433
diff --git a/packages/media-parser/src/containers/mp3/parse-xing.ts b/packages/media-parser/src/containers/mp3/parse-xing.ts
index 9885795024..3dce5b46c1 100644
--- a/packages/media-parser/src/containers/mp3/parse-xing.ts
+++ b/packages/media-parser/src/containers/mp3/parse-xing.ts
@@ -88,8 +88,9 @@ export const parseXing = (data: Uint8Array): XingData => {
offset += 4;
}
- if (offset !== data.length) {
- throw new Error('xing header was parsed wrong: ' + JSON.stringify(data));
+ // Allow extra data after the standard Xing fields, as some encoders add additional information
+ if (offset > data.length) {
+ throw new Error('xing header was parsed wrong: read beyond available data');
}
return {
diff --git a/packages/media-parser/src/test/xing-parsing-bug.test.ts b/packages/media-parser/src/test/xing-parsing-bug.test.ts
index 86027a7e22..64ed76d36a 100644
--- a/packages/media-parser/src/test/xing-parsing-bug.test.ts
+++ b/packages/media-parser/src/test/xing-parsing-bug.test.ts
@@ -1,40 +1,36 @@
import {expect, test} from 'bun:test';
-import {parseMedia} from '../parse-media';
import {nodeReader} from '../node';
+import {parseMedia} from '../parse-media';
-test('Xing parsing bug - problematic MP3 files', async () => {
+test('Xing parsing bug - problematic MP3 files should parse successfully', async () => {
const file1Path = '/tmp/test-mp3s/file1.mp3';
const file2Path = '/tmp/test-mp3s/file2.mp3';
- // Test file 1
- try {
- await parseMedia({
- src: file1Path,
- reader: nodeReader,
- acknowledgeRemotionLicense: true,
- fields: {
- durationInSeconds: true,
- },
- });
- console.log('File 1 parsed successfully');
- } catch (error) {
- console.log('File 1 error:', error.message);
- expect(error.message).toContain('xing header was parsed wrong');
- }
+ // Test file 1 - should now parse successfully
+ await parseMedia({
+ src: file1Path,
+ reader: nodeReader,
+ acknowledgeRemotionLicense: true,
+ fields: {
+ durationInSeconds: true,
+ },
+ onDurationInSeconds: (duration) => {
+ expect(typeof duration).toBe('number');
+ expect(duration).toBeGreaterThan(0);
+ },
+ });
- // Test file 2
- try {
- await parseMedia({
- src: file2Path,
- reader: nodeReader,
- acknowledgeRemotionLicense: true,
- fields: {
- durationInSeconds: true,
- },
- });
- console.log('File 2 parsed successfully');
- } catch (error) {
- console.log('File 2 error:', error.message);
- expect(error.message).toContain('xing header was parsed wrong');
- }
-});
\ No newline at end of file
+ // Test file 2 - should now parse successfully
+ await parseMedia({
+ src: file2Path,
+ reader: nodeReader,
+ acknowledgeRemotionLicense: true,
+ fields: {
+ durationInSeconds: true,
+ },
+ onDurationInSeconds: (duration) => {
+ expect(typeof duration).toBe('number');
+ expect(duration).toBeGreaterThan(0);
+ },
+ });
+});