Skip to content

🎥 Make videos programmatically with React

`@remotion/media-parser`: Fix MP3 with ID3 syncsafe box sizes

Jonny Burger9be72e46ab91
diff --git a/packages/compositor/rust/opened_stream.rs b/packages/compositor/rust/opened_stream.rs
index 539a58452f..6aed47f27d 100644
--- a/packages/compositor/rust/opened_stream.rs
+++ b/packages/compositor/rust/opened_stream.rs
@@ -433,7 +433,7 @@ impl OpenedStream {
return Err(std::io::Error::new(
ErrorKind::Other,
format!(
- "No frame found at position {} for source {} (original source = {}). If you think this should work, file an issue at https://remotion.dev/issue or post it in https://remotion.dev/discord. Post the problematic video and the output of `npx remotion versions`.",
+ "No frame found at position {} for source {} (original source = {}). If you think this should work, file an issue at https://remotion.dev/report or post it in https://remotion.dev/discord. Post the problematic video and the output of `npx remotion versions`.",
target_position, self.src, self.original_src
),
))?;
diff --git a/packages/convert/app/components/ErrorState.tsx b/packages/convert/app/components/ErrorState.tsx
index 81d209e3a6..b2453a0cc7 100644
--- a/packages/convert/app/components/ErrorState.tsx
+++ b/packages/convert/app/components/ErrorState.tsx
@@ -57,10 +57,10 @@ export const ErrorState: React.FC<{
Report this issue on{' '}
<a
target="_blank"
- href="https://remotion.dev/issue"
+ href="https://remotion.dev/report"
className="underline"
>
- remotion.dev/issue
+ remotion.dev/report
</a>{' '}
and upload the video. We&apos;ll try our best to help!
</div>
diff --git a/packages/example-videos/src/index.ts b/packages/example-videos/src/index.ts
index bc149a095d..6274cc6243 100644
--- a/packages/example-videos/src/index.ts
+++ b/packages/example-videos/src/index.ts
@@ -78,6 +78,7 @@ export const exampleVideos = {
),
unknown: __filename,
unevendim: path.join(__dirname, '..', 'videos', 'unevendim.webm'),
+ syncsafe: path.join(__dirname, '..', 'videos', 'syncsafe-id3.mp3'),
};
export {getRemoteExampleVideo, remoteExampleVideos} from './remote-videos';
diff --git a/packages/example-videos/videos/syncsafe-id3.mp3 b/packages/example-videos/videos/syncsafe-id3.mp3
new file mode 100644
index 0000000000..409743b059
Binary files /dev/null and b/packages/example-videos/videos/syncsafe-id3.mp3 differ
diff --git a/packages/media-parser/src/buffer-iterator.ts b/packages/media-parser/src/buffer-iterator.ts
index b55d6b34b9..ce1bfad692 100644
--- a/packages/media-parser/src/buffer-iterator.ts
+++ b/packages/media-parser/src/buffer-iterator.ts
@@ -189,6 +189,18 @@ export const getArrayBufferIterator = (
return val;
};
+ const getSyncSafeInt32 = () => {
+ const val = view.getUint32(counter.getDiscardedOffset());
+ counter.increment(4);
+
+ return (
+ ((val & 0x7f000000) >> 3) |
+ ((val & 0x007f0000) >> 2) |
+ ((val & 0x00007f00) >> 1) |
+ (val & 0x0000007f)
+ );
+ };
+
const getUint64 = (littleEndian = false) => {
const val = view.getBigUint64(counter.getDiscardedOffset(), littleEndian);
counter.increment(8);
@@ -683,6 +695,7 @@ export const getArrayBufferIterator = (
readExpGolomb,
startCheckpoint,
getFlacCodecNumber,
+ getSyncSafeInt32,
};
};
diff --git a/packages/media-parser/src/containers/mp3/id3.ts b/packages/media-parser/src/containers/mp3/id3.ts
index 8e7ea7d279..323387f4ef 100644
--- a/packages/media-parser/src/containers/mp3/id3.ts
+++ b/packages/media-parser/src/containers/mp3/id3.ts
@@ -45,9 +45,11 @@ export const parseId3 = ({state}: {state: ParserState}) => {
}
const s =
- versionMajor === 3 || versionMajor === 4
- ? iterator.getUint32()
- : iterator.getUint24();
+ versionMajor === 4
+ ? iterator.getSyncSafeInt32()
+ : versionMajor === 3
+ ? iterator.getUint32()
+ : iterator.getUint24();
if (versionMajor === 3 || versionMajor === 4) {
iterator.getUint16(); // flags
}
diff --git a/packages/media-parser/src/internal-parse-media.ts b/packages/media-parser/src/internal-parse-media.ts
index 2ddc732394..c1f09c7a60 100644
--- a/packages/media-parser/src/internal-parse-media.ts
+++ b/packages/media-parser/src/internal-parse-media.ts
@@ -225,7 +225,7 @@ export const internalParseMedia: InternalParseMedia = async function <
if (iterationWithThisOffset > 300) {
throw new Error(
- 'Infinite loop detected. The parser is not progressing. This is likely a bug in the parser.',
+ 'Infinite loop detected. The parser is not progressing. This is likely a bug in the parser. You can report this at https://remotion.dev/report and we will fix it as soon as possible.',
);
}
diff --git a/packages/media-parser/src/test/mp3-syncsafe.test.ts b/packages/media-parser/src/test/mp3-syncsafe.test.ts
new file mode 100644
index 0000000000..032419db98
--- /dev/null
+++ b/packages/media-parser/src/test/mp3-syncsafe.test.ts
@@ -0,0 +1,14 @@
+import {test} from 'bun:test';
+import {parseMedia} from '../parse-media';
+import {nodeReader} from '../readers/from-node';
+
+test('should respect syncsafe tag sizes', async () => {
+ await parseMedia({
+ src: '/Users/jonathanburger/Downloads/silence-with-artwork.mp3',
+ reader: nodeReader,
+ fields: {
+ durationInSeconds: true,
+ },
+ acknowledgeRemotionLicense: true,
+ });
+});