Skip to content

Truly independent web browser

LibMedia: Report short ISO BMFF reads at the data end as end of stream

Andreas Kling9c95ac1d46bf
diff --git a/Libraries/LibMedia/Containers/ISOBMFF/Streamer.h b/Libraries/LibMedia/Containers/ISOBMFF/Streamer.h
index 1bf7cbc2332..bca56e87f83 100644
--- a/Libraries/LibMedia/Containers/ISOBMFF/Streamer.h
+++ b/Libraries/LibMedia/Containers/ISOBMFF/Streamer.h
@@ -30,7 +30,7 @@ public:
if (count != sizeof(T)) {
auto size = m_stream_cursor->size();
if (size.has_value() && (start > size.value() || sizeof(T) > size.value() - start))
- return DecoderError::corrupted("Unexpected end of ISO BMFF stream"sv);
+ return DecoderError::with_description(DecoderErrorCategory::EndOfStream, "Unexpected end of ISO BMFF stream"sv);
// Non-blocking cursors return short reads when a range has not arrived (or was evicted).
return DecoderError::with_description(DecoderErrorCategory::NeedsMoreInput, "ISO BMFF data is not available yet"sv);
}
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.ini
index a3b4e1d11b9..ea27ead5998 100644
--- a/Tests/LibWeb/TestConfig.ini
+++ b/Tests/LibWeb/TestConfig.ini
@@ -55,6 +55,7 @@ Text/input/WebAudio/BaseAudioContext-decodeAudioData-undecodable-bytes.html
Text/input/HTML/media-source-abort-resets-parser.html
Text/input/HTML/media-source-addtrack-events.html
Text/input/HTML/media-source-adjacent-appends.html
+Text/input/HTML/media-source-split-initialization-segment.html
Text/input/HTML/media-source-append-window-trims-audio.html
Text/input/HTML/media-source-buffered.html
Text/input/HTML/media-source-duration.html
diff --git a/Tests/LibWeb/Text/expected/HTML/media-source-split-initialization-segment.txt b/Tests/LibWeb/Text/expected/HTML/media-source-split-initialization-segment.txt
new file mode 100644
index 00000000000..bbb8d2c641d
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/HTML/media-source-split-initialization-segment.txt
@@ -0,0 +1,4 @@
+Split at 2: error fired: false, video tracks: 1, audio tracks: 1
+Split at 42: error fired: false, video tracks: 1, audio tracks: 1
+Split at 627: error fired: false, video tracks: 1, audio tracks: 1
+Split at 1066: error fired: false, video tracks: 1, audio tracks: 1
diff --git a/Tests/LibWeb/Text/input/HTML/media-source-split-initialization-segment.html b/Tests/LibWeb/Text/input/HTML/media-source-split-initialization-segment.html
new file mode 100644
index 00000000000..c8f59739dd8
--- /dev/null
+++ b/Tests/LibWeb/Text/input/HTML/media-source-split-initialization-segment.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<script>
+ // An append may end partway through a value in the initialization segment. The source buffer must wait for the rest
+ // of the segment rather than treat the bytes it has as corrupt.
+ asyncTest(async done => {
+ const mimeType = 'video/mp4;codecs="av01.0.00M.08,mp4a.40.2"';
+ const data = new Uint8Array(await (await fetch("../../../Assets/av1-aac-fragmented.mp4")).arrayBuffer());
+ const view = new DataView(data.buffer);
+ const fileTypeBoxSize = view.getUint32(0);
+ const initializationSegment = data.subarray(0, fileTypeBoxSize + view.getUint32(fileTypeBoxSize));
+
+ async function appendInTwoParts(splitOffset) {
+ const video = document.createElement("video");
+ const mediaSource = new MediaSource();
+ video.src = URL.createObjectURL(mediaSource);
+ await new Promise(resolve => mediaSource.addEventListener("sourceopen", resolve, { once: true }));
+ const sourceBuffer = mediaSource.addSourceBuffer(mimeType);
+ let errorFired = false;
+ sourceBuffer.addEventListener("error", () => errorFired = true);
+
+ for (const part of [initializationSegment.subarray(0, splitOffset), initializationSegment.subarray(splitOffset)]) {
+ sourceBuffer.appendBuffer(part);
+ await new Promise(resolve => sourceBuffer.addEventListener("updateend", resolve, { once: true }));
+ }
+ println(`Split at ${splitOffset}: error fired: ${errorFired}, video tracks: ${video.videoTracks.length}, audio tracks: ${video.audioTracks.length}`);
+ }
+
+ // Split two bytes into the size of the File Type box, of the Movie Header box, of the second Track box, and of
+ // the last Chunk Offset box's entry count.
+ for (const splitOffset of [2, fileTypeBoxSize + 10, 627, 1066])
+ await appendInTwoParts(splitOffset);
+ done();
+ });
+</script>