Repository navigation
wasm-reduce: Fix integer overflows - #8665
Conversation
| std::unique_ptr<Builder> builder; | ||
| Index funcsSeen; | ||
| int factor; | ||
| size_t factor; |
There was a problem hiding this comment.
Should we just make it uint64_t / int64_t if we're worried about overflowing a 32-bit int? I guess some systems may have 4 bytes for size_t?
There was a problem hiding this comment.
Hmm, I guess we could. I feel size_t reads a bit better, and a 32-bit system couldn't load a wasm file this large anyhow?
There was a problem hiding this comment.
I usually prefer explicit sizes to not have to worry about differences in architecture, e.g. when reading I might wonder if the code works for 64-bit size_t but not for 32-bit size_t. I don't have a strong preference though, LGTM.
There was a problem hiding this comment.
Ok, I'm convinced. Changed to uint64_t.
Use a larger size than int, and be careful when multiplying by 9.
cc @tlively , I noticed that reducing a huge file - perhaps of a similar size as the one you were looking at - hit an overflow and immediately went to factor=1, which was extremely slow.