Heap buffer overflow in `read_to_end_with_reservation()`
Qwaz opened this issue · 3 comments
rust/library/std/src/io/mod.rs
Lines 358 to 403 in c97f11a
At line 393, the guard object's .len
field is incremented by the value returned from a read implementation. If a questionable Read
returns a value larger than the buffer size, it will take that value and set the length of the vector over the boundary.
This bug is reachable from Read::read_to_end()
and Read::read_to_string()
.
Here is a playground link that demonstrates the bug. It segfaults with double free or corruption (out)
.
This is definitely broken - nice find.
A simple fix would be to just add an assert!(self.len <= self.buf.len());
in the drop impl:
rust/library/std/src/io/mod.rs
Lines 302 to 306 in c97f11a
You can still get weird behavior in read_to_end_with_reservation, but it should be memory safe and it seems best to avoid a bunch of extra logic in the main loop.
Assigning P-critical
as discussed as part of the Prioritization Working Group procedure and removing I-prioritize
.