Fix UsedWays bounds check#903
Open
Symmetricity wants to merge 1 commit into
Open
Conversation
UsedWays stores relation-used way ids in a vector<bool>. The old exact-size check treated wayid == size() as valid and then indexed one past the vector. Resize when the requested id is equal to the current size, and treat the same boundary as absent when reading. Add coverage for the first and exact-size insert cases. Co-authored-by: Codex <noreply@openai.com>
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.
This PR is AI generated.
Summary
UsedWaysbounds checks when the requested way id is exactly thecurrent
usedList.size()Background
UsedWaysstores relation-used way ids in astd::vector<bool>. Its existingchecks used
wayid > usedList.size(), then indexedusedList[wayid]. Whenwayid == usedList.size(), that is one past the end of the vector.That can produce undefined behavior in both directions:
insert()can write past the end instead of growing the vector firstat()can read past the end instead of returningfalseI checked the history around this code. The surrounding
UsedWaysstorage wasintroduced for memory savings, and later retained during relation-processing
changes, but I did not find a rationale for treating the exact-size boundary as
valid.
Change
Use
>=for the resize/read boundary so the vector grows before an exact-endwrite, and exact-end reads are reported as absent.
This keeps the existing growth strategy and data structure unchanged.
Expected Behavior
There should be no intended output change except avoiding undefined behavior at
the vector boundary. The exact-boundary case now grows by the same
+256increment that nearby out-of-range ids already used.
Testing
git diff --checkmake test_osm_storectest --output-on-failure(no CMake tests are registered in this repo)