-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Candid deserialization of large arrays fails with buffer overflow on read #3068
Comments
Could you bisect the failing array length? Knowing the shortest array where it fails may give us a good lead. |
Nope, not yet. My suspicion is that our Rust leb128 encoders might be dodgy, but it's just a hunch. |
I think the leb decoders are ok, and am now suspecting that we don't check for overflow when pre-computing the size of the serialized blob during serialization. I can't see an overflow check in the code. @nomeata, seem plausible? |
FTR, the problem was an missing overflow check in alloc_word... Be afraid, be very afraid. |
Fixes two classes of `u32`-undetected overflow bugs that could corrupt heap, stable variables, or both: * ic.rs: `alloc_words` wasn't checking validity of addresses, leading to possible (and observed) heap corruption. * compile.ml: `buffer_size` wasn't checking overflow of 32-bit size pre-computation. The first is fixed using an overflow detecting add function of Rust. The second is checked by using a local `i64` in each type-directed size function. These functions are MV and return two `i32`s (for the data buffer and (vestigial) reference buffer sizes. I did not modify the functions to return 2 `i64`s because our MultiValue emulation only support `i32` at the moment. Fixes #3068.
This was hard to reproduce locally using drun (perhaps because of my VM's resources) and annoying to repro with dfx because it refused to upgrade to code with the same hash.
But the playground was just right:
https://m7sm4-2iaaa-aaaab-qabra-cai.raw.ic0.app/?tag=336007141
Consider the code:
Deploying and then doing a self-upgrade produces the following crash (see the playground log)
I first noticed the bug locally on master (0.6.20), so the outdated moc version of the playground is not the culprit.
This seems to be the line that is trapping:
motoko/rts/motoko-rts/src/buf.rs
Line 23 in 91df5fd
Perhaps an error decoding the larger array size and payload range?
UPDATE: Got a drun repro #3067 (by decreasing array size)
The text was updated successfully, but these errors were encountered: