Repository navigation
Conversation
This branch has not been deployed
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.
S2Polyline::DecodeUncompressed reads the vertex count from the encoded header and writes it straight into num_vertices_, and only afterwards checks whether the decoder still holds that many S2Points. On a truncated or crafted encoding that check fails and Decode() returns false, but the polyline is now left claiming N vertices while vertices_ still points at whatever buffer it had before, so a later vertex(), ApproxEquals(), Encode() or copy construction reads past that allocation. I hit it by cutting an uncompressed encoding one vertex short and decoding it into a two-vertex polyline: num_vertices() came back as 4 and AddressSanitizer reported a heap-buffer-overflow read 24 bytes past the 48-byte vertex buffer. The same check also multiplies the count by sizeof(S2Point) in size_t, which wraps on 32-bit targets and can admit a count whose allocation is far smaller than num_vertices_. S2Loop::DecodeInternal already does all of its checks before touching vertex state, and S2Polyline::DecodeCompressed decodes into a local vector, so the uncompressed path was the odd one out. The fix reads the count into a local, compares it against avail() / sizeof(S2Point), and only then updates num_vertices_ and allocates; a regression test covers the truncated case and fails before this change.