← All issues

[cocoa] AVStreamDataParser accepts media segments not preceded by an init segment

4ed0007

LayoutTests/media/media-source/media-source-append-media-before-init.html

+function makeFreeBox(size) {
+ var buffer = new ArrayBuffer(size);
+ var view = new DataView(buffer);
+ view.setUint32(0, size);
+ view.setUint32(4, 0x66726565); // 'free'
+ return buffer;
+}

WebKit's MSE implementation on Cocoa delegates ISO-BMFF parsing to AVStreamDataParser, an AVFoundation private API. The MSE spec mandates a strict ordering: an initialization segment (ftyp+moov) must precede any media segment (moof+mdat). AVStreamDataParser does not enforce this itself — it produces CMSampleBuffers with null CMFormatDescription that fail downstream. Mid-stream format changes (a new ftyp arriving without a preceding abort()/changeType()) trigger an internal CoreMedia -16046 error from MoofManifold that is swallowed silently.

This commit adds a new ISOBMFFPreParser upstream of AVStreamDataParser. It walks ISO-BMFF box headers across appendData() boundaries — without parsing box contents — to reject media segments before any init segment and inject an AVStreamDataParserStreamDataDiscontinuity signal when a new ftyp appears mid-stream. The pre-parser uses BitReader rather than the existing ISOBox::peekBox (which requires JSC::DataView and routes through Gigacage) because SharedBuffer contents are not Gigacage-allocated and that path faults with EXC_BAD_ACCESS. The previously dead AppendFlags::Discontinuity code path is activated for the first time outside abort()/changeType().

A new stateful binary parser now sits in front of AVStreamDataParser on Apple platforms, walking ISO-BMFF box headers across appendData() boundaries on attacker-supplied, non-Gigacaged memory.

🔒

The new binary pre-parser has several edge cases in its size-field decoding, cross-boundary reassembly, and append-split logic worth security investigation.

Subscribe to read more