fix(runtime): validate preinstalled shape key counts - #9283
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
Included review availability: Your plan provides up to 8 included reviews per hour; 3 remain after this review. 📝 WalkthroughWalkthroughThe runtime now validates the logical key count of a preinstalled shape before birth-stamping. A mismatch triggers exact descriptor fallback. A regression test covers stale module keys. ChangesShape key-count validation
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This localized runtime fix rejects stale shape metadata before publication and falls back to an exact descriptor, preserving object-header consistency. No actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Full details: Linked Issues checkExplanation The changes satisfy issue [ Full details: Docstring CoverageExplanation Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. (1 skipped: 1 unsupported.) Full details: Description checkExplanation The description includes all required sections, explains the ShapeId validation change, references issue ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Audited the diff — this addresses the root cause and I'd merge it. One question at the end that I would not block on. The fix lands exactly where #9265's assertion pointed. d.keys == keys as u64 && d.logical_key_count == key_count…but the direct-stamp fast path only proved the keys pointer and the live-slot bound. It justified skipping the count with this reasoning, which the diff removes:
The replacement is the important part: the id and the keys pointer arrive through separate module globals, so that identity does not in fact carry the count, and the two can drift. Computing The regression test is genuine rather than a restatement: it mints an id for a length-1 keys array, mutates Question, not a blockerThis makes the allocator tolerant of divergence rather than preventing it. If the two globals drifting apart is a legitimate consequence of independent publication, that is exactly right. If drift instead indicates something upstream corrupting or reusing a keys array, this fix would make the symptom disappear while leaving that cause in place — and the assertion that caught it is a The comment says this is the state "fast-json-stringify reached through AJV's resolve module" — if that path is understood well enough to say the drift is expected there, I am satisfied. Worth a sentence in the PR either way, since the next person reading this will ask the same thing. |
78dcfb7 to
bc89231
Compare
|
Merged. Validating the current logical key count alongside the keys pointer before birth-stamping a preinstalled ShapeId is the right shape: the failure mode is a ShapeId that claims a structure the separately-supplied keys global no longer has, and the only safe answer when those two disagree is to fall back to the exact-descriptor path rather than publish a shape nobody can trust. I probed the disagreement directly rather than the happy path — 200 class instances plus 150 object literals, then Validation: |
Summary
Fix the release-blocking ShapeId/ObjectHeader publication disagreement reached by fast-json-stringify. A preinstalled class ShapeId is now birth-stamped only when its descriptor agrees with every current structural fact from the separately supplied keys global; otherwise the existing exact-descriptor fallback runs.
Changes
Related issue
Fixes #9265
Test plan
Run on
root@perrymaster.skelpo.net:cargo fmt --all -- --checkgit diff --checkcargo test -p perry-runtime preinstalled_shape -- --nocapturecargo build -p perry -p perry-runtime-static -p perry-stdlib-staticRUST_TEST_THREADS=1 cargo test -p perry --test issue_6559_real_libs_e2e real_fast_json_stringify_serializer -- --nocaptureAdditional repository check:
./scripts/check_file_size.shScreenshots / output
The exact issue reproducer passes: 1 passed, 0 failed.
Checklist
Summary by CodeRabbit