Prevent clearing flag gradients from reading past resource switches - #181
Prevent clearing flag gradients from reading past resource switches#181genixpro wants to merge 4 commits into
Conversation
|
Verification and policy follow-up on
New CI is pending. Correcting undefined behavior can change clearing paths relative to the unfixed engine; same save format does not imply mixed-version simulation compatibility. @Giszmo @kylelutze, please independently review the bounds fix and this verification before merging. This will not be self-merged. |
Giszmo
left a comment
There was a problem hiding this comment.
Verified against master bfc8fd7: clearingResources is bool[BASIC_COUNT] followed by Sint32 minLevelToFlag, so fruit IDs 5-7 read the padding bytes; both gradient builders now use the same < BASIC_COUNT guard that updateLocalResources and Map::isResourceTakeable already had. CI green on all three jobs. Approving.
There was a problem hiding this comment.
Removed the dedicated reproduction document in edbb6ae. The test command and coverage now live in the existing test/README.md; the before/after evidence stays on this PR.
There was a problem hiding this comment.
why does every test need a python runner?
There was a problem hiding this comment.
Agreed. edbb6ae deletes the clearing-specific Python runner and reuses run-savegame-safety-tests.py with an optional --check-preferences flag. Clearing and the existing save-safety suite both pass on Ubuntu 24.04/GCC 13. The shared runner uses a disposable HOME and working directory. New Linux/Windows CI is pending; please re-review this follow-up. The production bounds checks are unchanged.
|
Updated to current master in 9e2f6b5 and resolved the merge conflicts. Master removed local gradients and changed building gradients to 16-bit values, so the retained test now exercises the current API and every swimming class. The remaining production change is the same resource-index bounds check. Optimized clearing and shared save-safety regressions pass on macOS and Ubuntu 24.04. Targeted ASan/UBSan passes on Linux with leak detection disabled; the unfixed master source triggers index 5 out of bounds for bool[5]. CI on this final head now passes on Ubuntu 22.04, Ubuntu 24.04 and Windows, including the clearing regression and savegame-safety checks. @kylelutze, the document and dedicated-runner requests remain addressed; your re-review request is still open. This has not been merged. |
|
Resolve conflicts and merge |
A clearing flag has five basic-resource switches, but fruit IDs are 5–7. The building-gradient builder indexed that array with any nonempty resource ID, reading object padding for fruit. Different allocation histories, including loading a save, could therefore change clearing targets and unit paths.
Check
resource.type < BASIC_COUNTbefore indexing the switches. Fruit remains an obstacle, consistent with the supported switches. No serialized layout changes; mixed-version replay/network equivalence is not established because the invalid read can affect paths.Regression
Use
.exeon Windows. The real-engine fixture varies only padding after the switch array and checks every fruit, enabled/disabled basic-resource switches, empty tiles, and all swimming classes. It uses the existing shared runner with a disposable profile and working directory, and verifies preference preservation. Linux and Windows CI execute it.Review follow-up and validation
Removed the standalone regression document and dedicated Python runner as requested. Concise usage remains in the existing test README. Follow-up
9e2f6b5f0incorporates current master: its local-gradient implementation has been removed, so the test now covers the current 16-bit weighted building gradient and all swimming classes. The remaining production fix is one bounds check.macOS / Apple Clang and Ubuntu 24.04 / GCC 13: the updated optimized clearing regression and existing savegame-safety harness pass. Targeted ASan/UBSan instrumentation of
MapGradientBuilding.cppand the fixture passes against optimized engine objects. The negative control substitutes the unfixed source from master88934ecfband fails on the out-of-bounds fruit index. Leak detection is disabled because of the separately observed script-binding leak; this is not a full-engine sanitizer or leak-clean claim.Final-head CI passes on Ubuntu 22.04, Ubuntu 24.04 and Windows. Kyle's re-review is pending. This author-owned submission requires separate review and merge.