File: 1907222_truncate_error.html

package info (click to toggle)
firefox 144.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,637,504 kB
  • sloc: cpp: 7,576,692; javascript: 6,430,831; ansic: 3,748,119; python: 1,398,978; xml: 628,810; asm: 438,679; java: 186,194; sh: 63,212; makefile: 19,159; objc: 13,086; perl: 12,986; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (53 lines) | stat: -rw-r--r-- 2,244 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<!DOCTYPE html>
<html class="reftest-wait">
  <head>
    <meta charset="utf-8" />
    <script src="/tests/SimpleTest/SimpleTest.js"></script>
    <link rel="stylesheet" href="/tests/SimpleTest/test.css" />
  </head>
  <body>
    <script>
      // Ensure that, when WebGPU generates an error message that is later
      // truncated by `wgpu_bindings::error::ErrorBuffer::init`, that
      // truncation always produces valid UTF-8, even when the error contains
      // multi-byte encodings.
      async function truncate_error_messages() {
        // The specific error we'll try to provoke is submitting a command
        // buffer to the wrong device's queue.
        const adapter = await navigator.gpu.requestAdapter();
        const device1 = await adapter.requestDevice();
        const device2 = await adapter.requestDevice();

        // Try a range of label lengths (578±200, where 578 is the length that
        // tickles the original bug), searching for one that, when combined with
        // the error message and then truncated at whatever error message byte
        // length limit Firefox is imposing, will produce invalid UTF-8.
        //
        // Use a label containing n space characters followed by a crab emoji,
        // U+1F980, which requires four bytes to encode in UTF-8. Since this has
        // a four-byte encoding at the end, we only need to try every third
        // length to ensure we will always try a truncation point in the midst
        // of that encoding.
        for (let len = 378; len < 778; len += 3) {
          const label = ' '.repeat(len) + '\uD83E\uDD80';
          const encoder = device1.createCommandEncoder({ label });
          const command_buffer = encoder.finish();

          // We don't want an error scope around this, because what makes
          // Firefox notice the bad UTF-8 is attempting to log the uncaught
          // WebGPU error as a warning.
          device2.queue.submit([command_buffer]);
        }
      }

      truncate_error_messages()
        .catch(e => {
          console.log(e);
        })
        .finally(() => {
          // End the crashtest.
          document.documentElement.removeAttribute("class");
        });
    </script>
  </body>
</html>