Skip to content

🎥 Make videos programmatically with React

Fix reported problem

JonnyBurger3a631eaafc49
diff --git a/packages/media-parser/src/containers/flac/get-block-size.ts b/packages/media-parser/src/containers/flac/get-block-size.ts
index c65e577568..c174e4543e 100644
--- a/packages/media-parser/src/containers/flac/get-block-size.ts
+++ b/packages/media-parser/src/containers/flac/get-block-size.ts
@@ -2,10 +2,13 @@ import type {BufferIterator} from '../../iterator/buffer-iterator';
export const getBlockSize = (
iterator: BufferIterator,
-): number | 'uncommon-u16' | 'uncommon-u8' => {
+): number | 'uncommon-u16' | 'uncommon-u8' | null => {
const bits = iterator.getBits(4);
if (bits === 0b0000) {
- throw new Error('Reserved block size');
+ // Probably we are in the wrong spot overall, and just landed on a spot that incidentially hit the syncword.
+ // Don't throw an error, in the parent function just keep reading.
+ // Internal message with repro: https://discord.com/channels/@me/1314232261008162876/1410312296709881988
+ return null;
}
if (bits === 0b0001) {
diff --git a/packages/media-parser/src/containers/flac/parse-flac-frame.ts b/packages/media-parser/src/containers/flac/parse-flac-frame.ts
index 6d4a9add9d..da5b22a411 100644
--- a/packages/media-parser/src/containers/flac/parse-flac-frame.ts
+++ b/packages/media-parser/src/containers/flac/parse-flac-frame.ts
@@ -49,6 +49,10 @@ export const parseFrameHeader = ({
iterator.discard(2); // sync code
iterator.startReadingBits();
const blockSizeBits = getBlockSize(iterator);
+ if (blockSizeBits === null) {
+ return null;
+ }
+
const sampleRateBits = getSampleRate(iterator, state);
getChannelCount(iterator); // channel count
iterator.getBits(3); // bit depth