tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

invalid-third-block.html (2423B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <meta charset=utf-8>
      5 <title>Unknown Track Number in Third Block</title>
      6 <script src="/resources/testharness.js"></script>
      7 <script src="/resources/testharnessreport.js"></script>
      8 <script src="mediasource-util.js"></script>
      9 </head>
     10 <body>
     11 </body>
     12 <script>
     13 // Test that an unknown track number in the third webm block triggers the
     14 // append error algorithm.
     15 // https://w3c.github.io/media-source/#byte-stream-formats
     16 // The user agent MUST run the append error algorithm when any combination of
     17 // an initialization segment and any contiguous sequence of media segments
     18 // satisfies the following conditions:
     19 // 1. The number and type (audio, video, text, etc.) of all tracks in the
     20 //    media segments are not identified.
     21 promise_test(async t => {
     22  const audio = document.createElement('audio');
     23  audio.controls = true;
     24  audio.watcher = new EventWatcher(t, audio, ['error']);
     25  document.body.appendChild(audio);
     26 
     27  const source = new MediaSource();
     28  source.watcher = new EventWatcher(t, source, ['sourceopen']);
     29  audio.src = URL.createObjectURL(source);
     30  await source.watcher.wait_for('sourceopen');
     31 
     32  const resource = await MediaSourceUtil.fetchResourceOfManifest(
     33    t, 'webm/test-a-128k-44100Hz-1ch-manifest.json');
     34  assert_implements_optional(MediaSource.isTypeSupported(resource.type),
     35                             `${resource.type} supported`);
     36 
     37  const buffer = source.addSourceBuffer(resource.type);
     38  buffer.watcher = new EventWatcher(t, buffer, ['error', 'updateend']);
     39  // Intentionally append data ending at the end of a cluster having an
     40  // invalid track number in a block that is after the second block in the
     41  // cluster, because Gecko had a bug that failed to detect some demux errors
     42  // in this situation.
     43  resource.data = resource.data.subarray(0, resource.cluster_start[1]);
     44  // Choose a track number of zero, which is not in the init segment.
     45  const track_number = 0;
     46  // Set the high bit of an octet, for a single-octet EBML VINT.
     47  const track_number_vint = 1 << 7 | track_number;
     48  // Skip two bytes for the EBML element ID and data size, and overwrite the
     49  // track number.
     50  resource.data[Number(resource.block_start[2]) + 2] = track_number_vint;
     51 
     52  buffer.appendBuffer(resource.data);
     53  await Promise.all([
     54    buffer.watcher.wait_for(['error', 'updateend']),
     55    audio.watcher.wait_for('error'),
     56  ]);
     57 }, 'invalid-third-block');
     58 </script>
     59 </html>