Repository navigation
Support 64 bit limits for tables - #2767
Conversation
| } | ||
| result |= CheckLimits(loc, limits, UINT32_MAX, "elems"); | ||
| uint64_t absolute_max = limits.is_64 ? UINT64_MAX : UINT32_MAX; | ||
| result |= CheckLimits(loc, limits, absolute_max, "elems"); |
There was a problem hiding this comment.
Alternative: if (!limits.is_64) { .... } since limits is 64 bit.
| CHECK_RESULT(ReadU64Leb128(&max, "table max elem count")); | ||
| } | ||
| out_elem_limits->initial = initial; | ||
| out_elem_limits->max = max; |
There was a problem hiding this comment.
Can we just always read these as 64-bit values and leave it to validation to check them?
If not then at least I think we can limit this if/else to just the 4 lines that do that ReadUXXLeb128.
There was a problem hiding this comment.
How the code would it look like? The ReadU32Leb128 uses a pointer to return its value, and we cannot pass the address of an uint64_t value to it.
I would not delegate this check to validation (too late for me), but we could read a 64 bit value and throw an error for !is_64 && >UINT32_MAX values. I am not sure we could make the code much nicer though.
There was a problem hiding this comment.
Can we just always read U64 in this case?
There was a problem hiding this comment.
Always? For 32 bit tables, I think a >UINT32_MAX value is malformed.
There was a problem hiding this comment.
But won't the validator then take care of that?
There was a problem hiding this comment.
It is too late for that. See these tests:
https://github.com/WebAssembly/testsuite/blob/d76759e746f3564a03f6106ae19679742f2a1831/table.wast#L27
These must fail even if validation is disabled, since they are malformed. If I read the limits as U64, they will pass.
E.g. (table 5 1 funcref) with --no-check should work (and it does), but (table 0 0x1_0000_0000 funcref) should not.
|
Created another code variant. The new |
| ERROR_UNLESS(bytes_read > 0 && (is_64 || *out_value <= UINT32_MAX), | ||
| "unable to read u%s leb128: %s", is_64 ? "64" : "32", desc); | ||
| state_.offset += bytes_read; | ||
| return Result::Ok; |
There was a problem hiding this comment.
Can you just call ReadU32Leb128 / ReadU64Leb128 here?
e.g. return is_64 ? ReadU64Leb128(out_value, desc) : ReadU32Leb128(out_value, desc)
There was a problem hiding this comment.
Changed the code. The ReadU32Leb128 requires uint32_t pointer, so the number of lines does not dropped.
| } | ||
| uint32_t value = 0; | ||
| Result result = ReadU32Leb128(&value, desc); | ||
| *out_value = value; |
There was a problem hiding this comment.
I could add a if (result == Result::Ok) here
No description provided.