<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Parse the entire WebAssembly modules"
   href="https://bugs.webkit.org/show_bug.cgi?id=147393#c13">Comment # 13</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Parse the entire WebAssembly modules"
   href="https://bugs.webkit.org/show_bug.cgi?id=147393">bug 147393</a>
              from <span class="vcard"><a class="email" href="mailto:sukolsak&#64;gmail.com" title="Sukolsak Sakshuwong &lt;sukolsak&#64;gmail.com&gt;"> <span class="fn">Sukolsak Sakshuwong</span></a>
</span></b>
        <pre>Thanks.

(In reply to <a href="show_bug.cgi?id=147393#c10">comment #10</a>)
<span class="quote">&gt; 1. Use a do-while loop because it is more succinct and easier to read.</span >

Done.

<span class="quote">&gt; 2. Use a uint64_t local value instead of storing into the result directly.
&gt; Using the local allows the compiler to put it in a register, and register
&gt; operations are cheap.  We only incur the memory write to result at the end.</span >

Used a local value.

<span class="quote">&gt; 3. When the computation is done,
&gt;     (1) break out of the loop,
&gt;     (2) validate that the computed value is within size of a uint32,  and
&gt;     (3) copy the local value into the result.  
&gt; 
&gt; 4. The loop can loop while (value &lt; numeric_limits&lt;uint32_t&gt;::max()).  This
&gt; ensures that we don't overflow our uint64_t local value and that the
&gt; validation check in 3.2 will work as expected.</span >

As discussed on IRC, checking that (value &lt; numeric_limits&lt;uint32_t&gt;::max()) is not enough, because the bytes could be 0x80 0x80 0x80 0x80 0x80 ... . Checking that the number of bytes doesn't exceed 5 and that the fifth byte is &lt;= 0b00001111 should prevent that and also eliminate the need for uint64_t.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>