Comment #3 on issue 131924 by
j...@chromium.org: TCMalloc realloc() fails
The bug in the code actually has two consequences. The first, reported
here, is that we fail on a viable realloc. The second is that the code
will sometimes fail to achieve its goal of freeing memory when the target
(new_size) allocation is small. Specifically, a realloc to far less than
half the current size, will sometimes simply continue to use the current
allocated region. The conversion of upper_bound_to_shrink into int32 can
produce a garbage small number, so that the test:
new_size < upper_bound_to_shrink
can fail to detect the need to get a new (small) reallocation (and free the
larger original block).
As noted by Will, this should be upstreamed.
Try as I might, I couldn't find a way to exploit any security ramifications
of the potentially bogus values of either lower_bound_to_grow and/or
upper_bound_to_shrink. When new_size *happens* to be less than
lower_bound_to_grow (the latter being cast back to int64), it is certainly
safe to malloc up (int64)lower_bound_to_grow. In all other cases, we
allocate new_size, which is also plenty safe.