← All reports

[1] Heap over-read in EME `cenc` init-data PlayReady fallback

MediumWebCore Encrypted Media ExtensionsOOB

A DRM sanitiser that let the heap decide how long your init data was

b6f26e0

Medium. One page-script call drives a heap over-read in WebContent, but the page controls neither the neighbouring bytes nor the stopping point. The ceiling stays at crash or coarse reject oracle unless a later slice of the buffer reaches a length-trusting consumer.

Browser DRM support takes page-supplied binary blobs and must sanitize them before any decryption module sees them, which makes the sanitizer a parser of fully attacker-chosen bytes. WebKit routes those blobs through InitDataRegistry (the per-format validator for data passed to MediaKeySession.generateRequest()), which holds each blob in a SharedBuffer, a byte container whose size is explicit and whose contents carry no terminating zero. Every scan the sanitizer performs is expected to stay within that explicit size.

The angle: a page calling generateRequest("cenc", ...) with a zero-free blob on a GStreamer port can make the renderer read past the end of its own init-data allocation. The result is a crash at worst, plus at most a one-bit accept/reject signal about neighbouring heap bytes.

isPlayReadySanitizedInitializationData() builds a StringView from the raw init data to locate the start of the PlayReady XML. It handed buffer.span().data() to StringView::fromLatin1(const char*), which measures length with strlen(). The buffer comes straight from MediaKeySession.generateRequest() and is arbitrary binary that is not NUL-terminated, so strlen() runs past the end of the SharedBuffer allocation until it reaches a zero byte. A cenc blob that fails pssh extraction appears to fall back from sanitizeCenc() to this helper, and the new regression test drives zero-free cenc blobs at it. A blob with no NUL byte (for example, one at least kCencMaxBoxSize long and filled with non-zero bytes) becomes a heap over-read. If the rest of the function then slices buffer at startTag, a '<' found in the over-read region would also yield an out-of-range offset. Building the StringView from the Latin1Character span, as MockCDMFactory already does, keeps the view within buffer.size(), which closes the first read and guarantees that any startTag is in-bounds. The new test feeds three such blobs through the mock CDM and expects all three to reject.

Source/WebCore/Modules/encryptedmedia/InitDataRegistry.cpp

@@ bool isPlayReadySanitizedInitializationData(const SharedBuffer& buffer)
// The protection data starts with a 10-byte PlayReady version
// header that needs to be skipped over to avoid XML parsing
// errors.
- auto view = StringView::fromLatin1(byteCast<char>(buffer.span().data()));
+ StringView view { byteCast<Latin1Character>(buffer.span()) };
auto startTag = view.find('<');
if (startTag == notFound)
return false;

LayoutTests/media/encrypted-media/mock-MediaKeySession-generateRequest-cenc-unterminated-crash.html

+ function unterminatedInitData(size, lastByte)
+ {
+ var array = new Uint8Array(size);
+ array.fill(0x41);
+ if (lastByte !== undefined)
+ array[size - 1] = lastByte;
+ return array;
+ }
...
+ run('initData = unterminatedInitData(64 * 1024)');
+ run('promise = mediaKeySession.generateRequest("cenc", initData)');
...
+ run('initData = unterminatedInitData(16, 0x3c)');

The fix is one line in isPlayReadySanitizedInitializationData(). The old call passed byteCast<char>(buffer.span().data()), a bare const char*, into StringView::fromLatin1. The new code constructs StringView view { byteCast<Latin1Character>(buffer.span()) } from the buffer's std::span<const Latin1Character>, so the view's length is exactly buffer.size(). The following view.find('<') and the notFound early return are unchanged, but they now operate on an in-bounds view, so any returned startTag is a valid in-buffer offset. The commit also adds a layout test and its expected output. The test sends three zero-free cenc blobs to generateRequest(): a 64 KiB blob (described as "at least kCencMaxBoxSize long"), a 16-byte blob whose first box is not pssh, and a 16-byte blob whose only '<' is the final byte. Each promise is expected to reject.

Treating a length-delimited binary buffer as a NUL-terminated C string, so a terminator search sets the view length and its offsets are applied to the correctly bounded container.

Encrypted Media Extensions. EME is the Web API through which a page asks a Content Decryption Module (CDM) to obtain keys for protected media. MediaKeySession.generateRequest(initDataType, initData) accepts an arbitrary BufferSource as initData, so every byte is page-chosen.

Init-data sanitization. Before forwarding init data to a CDM, WebKit's InitDataRegistry parses and re-serializes it according to initDataType (cenc, keyids, webm), so only well-formed data reaches the CDM. The sanitizer exists because CDMs are often opaque, platform-supplied code that should not be handed raw page bytes.

cenc and pssh boxes. cenc init data is one or more ISO BMFF pssh (Protection System Specific Header) boxes. Each box carries a size, the box type pssh, a 16-byte DRM system ID, and a system-specific payload.

PlayReady header. PlayReady init data starts with a small binary version header followed by an XML document. The sanitizer finds where the XML begins by searching for '<'.

SharedBuffer and StringView. SharedBuffer is WebCore's byte container: its size is explicit, and its contents are not NUL-terminated. StringView is a non-owning (pointer, length) view over characters. It can be built from a std::span, which carries an explicit length, or from a bare const char*, whose length is found with a strlen-style NUL search.

This is a heap out-of-bounds read caused by a length-semantics mismatch between two StringView construction paths.

  Before:                                After:
  generateRequest("cenc", blob)          generateRequest("cenc", blob)
    └─► pssh parsing fails                 └─► pssh parsing fails
          └─► fromLatin1(span.data())            └─► StringView{ span }
                └─► NUL scan runs past                 └─► length == size()
                    buffer.size() into heap                  └─► find('<') in-buffer
                      └─► find('<') over heap                      └─► startTag < size()
                            └─► startTag may exceed size()
                                  └─► (if startTag slices buffer)
                                      out-of-range offset

In the left column, fromLatin1(const char*) receives only a pointer and derives the view length by searching for a zero byte. That is standard WTF StringView semantics, not a quirk of this call site. The page fully controls the contents of the SharedBuffer. When those contents contain no zero byte (the test's unterminatedInitData() fills everything with 0x41), the scan walks off the end of the allocation and keeps going until adjacent heap memory happens to contain a zero. The view's length then reflects heap layout rather than buffer.size(), and view.find('<') searches that whole over-long range.

A second stage is possible, shown by the left column's conditional final arrow. Whether it occurs depends on how the function consumes startTag after the notFound check. If the remainder slices or indexes buffer at startTag, as the comment about skipping the PlayReady header before XML parsing suggests, then a '<' found past the buffer end would produce an offset outside the buffer. The third test blob, whose only '<' is the last in-buffer byte, probes exactly that boundary.

Reachability runs through the cenc fallback. extractPsshBoxesFromCenc() returns std::nullopt when buffer.size() >= kCencMaxBoxSize, which covers the 64 KiB blob. A cenc blob that fails pssh extraction appears to fall back to this PlayReady-XML heuristic. The new regression test drives zero-free cenc blobs at exactly this fix, which is consistent with that routing, though the sanitizeCenc() dispatch itself is the condition that has to hold. For the 16-byte non-pssh blob, rejection happens either through the std::nullopt path or through an early ISOBox::peekBox size rejection; either way it ends on the same fallback.

The regression test makes the trigger concrete:

  1. A mock-CDM MediaKeySession is created, and generateRequest("cenc", unterminatedInitData(64 * 1024)) is called with 64 KiB of 0x41.
  2. The strict pssh path rejects the oversized blob (extractPsshBoxesFromCenc() returns std::nullopt at or above kCencMaxBoxSize), and the sanitizer is expected to fall through to isPlayReadySanitizedInitializationData().
  3. Before the fix, fromLatin1 scans past byte 65535 into whatever follows the allocation. After the fix, the view stops at buffer.size(), find('<') returns notFound, and the helper returns false.
  4. The 16-byte non-pssh blob repeats the path with a small allocation, where adjacent heap is more likely to hold live neighbouring objects.
  5. The 16-byte blob ending in 0x3c places a '<' at the last valid offset. Post-fix, startTag == size() - 1, which is in-bounds by construction.

Exploitability is gated by what the scanned bytes feed into. The code is reachable from web content on GStreamer ports (WPE/GTK) with a single generateRequest("cenc", ...) call, if the helper is compiled only there. The libxml includes sit under USE(GSTREAMER); whether the function itself is guarded is the condition that decides port reach, and the test drives the mock CDM. The page controls the buffer's size and contents but not the neighbouring memory, and before startTag is consumed the over-read bytes only feed view.find('<'). Nothing is handed back to script beyond whether the promise rejects. The open question for escalation is what happens to startTag downstream. If the offset slices buffer and the result reaches libxml or another length-trusting consumer without a hardened-span trap, the over-read region could feed a parser, and generateRequest()'s accept/reject outcome could act as a weak oracle about adjacent heap contents. Whether hardened std::span bounds checks are enabled on GStreamer port builds decides whether that slice traps or proceeds, and that is the invariant to check before treating this as more than a crash.

This vulnerability weakens memory safety in the WebContent process. The init-data sanitizer is supposed to touch only the bytes the page supplied. Before the fix, the length of the scanned region depended on whatever heap memory followed the SharedBuffer allocation, producing a heap over-read whose extent the page does not control. That read could crash the renderer if it runs into unmapped memory, and, if startTag slices the buffer, an out-of-range offset could trap or extend the read. Because the scanned bytes appear to feed only the '<' search and a boolean result, any information returned to the page would be a coarse accept/reject signal at most, not a byte-level disclosure.

Insight: this is a classic API-overload trap. StringView::fromLatin1(const char*) and the span constructor look interchangeable, but the pointer overload silently swaps explicit length for terminator-defined length, and .data() discards the length the SharedBuffer already carried. The deeper lesson is that an index computed on one view must never be applied to a different container: even a benign first read would leave view and buffer disagreeing about length, which is enough to manufacture an out-of-range offset. The correct idiom was already in the same file. extractKeyIDsKeyids(), roughly 150 lines above, passes byteCast<Latin1Character>(buffer.span()) to JSON::Value::parseJSON, and the fix converges on it.