]> git.lizzy.rs Git - rust.git/commit
std: Check for overflow in `str::repeat`
authorAlex Crichton <alex@alexcrichton.com>
Thu, 20 Sep 2018 16:31:14 +0000 (09:31 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 20 Sep 2018 16:31:53 +0000 (09:31 -0700)
commit8ac88d375e00c91a3db5d78852048322f88be3c1
treea69b188363aea298bd56d12c51be3a774bce2873
parentf7f4c500b46603386e940f116b469c7adc043a6d
std: Check for overflow in `str::repeat`

This commit fixes a buffer overflow issue in the standard library
discovered by Scott McMurray where if a large number was passed to
`str::repeat` it may cause and out of bounds write to the buffer of a `Vec`.
This bug was accidentally introduced in #48657 when optimizing the
`str::repeat` function. The bug affects stable Rust releases 1.26.0 to
1.29.0. We plan on backporting this fix to create a 1.29.1 release, and
the 1.30.0 release onwards will include this fix.

The fix in this commit is to introduce a deterministic panic in the case of
capacity overflow. When repeating a slice where the resulting length is larger
than the address space, there’s no way it can succeed anyway!

The standard library and surrounding libraries were briefly checked to see if
there were othere instances of preallocating a vector with a calculation that
may overflow. No instances of this bug (out of bounds write due to a calculation
overflow) were found at this time.

Note that this commit is the first steps towards fixing this issue,
we'll be making a formal post to the Rust security list once these
commits have been merged.
src/liballoc/slice.rs
src/liballoc/str.rs