[Webkit-unassigned] [Bug 147393] Parse the entire WebAssembly modules

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Fri Jul 31 14:22:25 PDT 2015


https://bugs.webkit.org/show_bug.cgi?id=147393

--- Comment #10 from Mark Lam <mark.lam at apple.com> ---
Comment on attachment 257910
  --> https://bugs.webkit.org/attachment.cgi?id=257910
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=257910&action=review

>>> Source/JavaScriptCore/wasm/WASMReader.cpp:83
>>> +    CHECK_READ(1);
>> 
>> Why not do everything in the loop?
> 
> It's just an optimization for small integers. If this seems like a micro-optimization, let me know and I will fix it.

I'm not sure that optimizing here will yield much difference because we're parsing values from an untrusted file, and we need to do all sorts of error checks anyway.  I suggest implementing this all as follows:

1. Use a do-while loop because it is more succinct and easier to read.
2. Use a uint64_t local value instead of storing into the result directly. Using the local allows the compiler to put it in a register, and register operations are cheap.  We only incur the memory write to result at the end.
3. When the computation is done,
    (1) break out of the loop,
    (2) validate that the computed value is within size of a uint32,  and
    (3) copy the local value into the result.  

4. The loop can loop while (value < numeric_limits<uint32_t>::max()).  This ensures that we don't overflow our uint64_t local value and that the validation check in 3.2 will work as expected.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-unassigned/attachments/20150731/e906b659/attachment.html>


More information about the webkit-unassigned mailing list