Repository navigation
Conversation
When Realloc grows a block into the free block below it, the block moves down and what is left of the two follows it. The header of that free block was written before the move, and starts inside the block's old place when the new size is at least that of the free block below, so it overwrote 8 bytes of the block before they were copied. When nothing was left, the header was written over the size of the next block, and a free block of length 0 was put on the free list. The header is now written after the move, and only when there is room for one; otherwise the free block is taken off the list. Growing a vector could lose two 4-byte elements this way.
SetString() read freed memory when its source was a string in the same buffer and making room for the copy moved the buffer. Assigning a string a part of itself could also lose its end, as shrinking the old string in place writes a free block header over it. SetString() now finds a source in the buffer again by its offset after allocating, and copies out a source inside the string it replaces.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PayloadBuffer::Reallocwhen growing into the free block below: defer writing the free-block header until after the block move so payload bytes are not overwritten beforememmove.Test plan
toolbelt/payload_buffer_test(or full Bazel/CMake test suite as used in CI)