fix(slab): wire validateLayout into all detectSlabLayout tier branches - #346
fix(slab): wire validateLayout into all detectSlabLayout tier branches#346Morenikeoa wants to merge 1 commit into
Conversation
validateLayout (checks accountsOff <= dataLen and that the bitmap region fits within the buffer) was wired into only 3 of 15 buildLayout* call sites in detectSlabLayout: V12_19, V12_17, V12_15. The other 12 (V12_1EP, V12_1, V_SETDEXPOOL, V1M2, V_ADL, V1M, V0, V1D x2 branches, V1D-legacy, V1, V1-legacy) returned their built layout directly with no consistency check. This codebase has shipped exactly this class of bug before (wrong slab tier sizes, wrong bitmap/account byte offsets) on tiers that, at the time, had no automated guard against it. If a future offset/size constant for any of the 12 previously-unguarded tiers were wrong, this defensive layer would not catch it and could silently propagate a bad layout into parseHeader/parseConfig/parseEngine/parseAccount. No currently-registered tier size actually violates the invariant — that's why this gap never surfaced as a test failure; it's a coverage gap in a defense-in-depth mechanism, not an active misparse. Fix: wrap every buildLayout*(...) return value in validateLayout(...) inside detectSlabLayout, including both branches of the V1D/V2 disambiguation path. Added a regression test in test/slab.test.ts that reads detectSlabLayout's source and asserts every buildLayout* call site is wrapped in validateLayout(...) — the most direct way to verify the wiring exists, since no real registered tier size can currently trigger an actual validateLayout throw (by construction, every SLAB_TIERS_* entry was computed to satisfy the invariant). Confirmed it fails against the prior code (15 call sites, only 3 wrapped) and passes against this fix (15/15 wrapped). Full suite (pnpm test): exit 0, all green, including "detectSlabLayout validateLayout coverage check passed!". Vitest portion unchanged at 851 passed | 31 skipped (882 total) — the new test lives in slab.test.ts, run via tsx outside the vitest-counted suite.
|
Warning Review limit reached
More reviews will be available in 40 minutes and 39 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ 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 |
Summary
validateLayout(checksaccountsOff <= dataLenand that the bitmap region fits within the buffer) was wired into only 3 of 15buildLayout*call sites indetectSlabLayout: V12_19, V12_17, V12_15. The other 12 (V12_1EP, V12_1, V_SETDEXPOOL, V1M2, V_ADL, V1M, V0, V1D ×2 branches, V1D-legacy, V1, V1-legacy) returned their built layout directly with no consistency check.This codebase has shipped exactly this class of bug before (wrong slab tier sizes, wrong bitmap/account byte offsets) on tiers that, at the time, had no automated guard against it. If a future offset/size constant for any of the 12 previously-unguarded tiers were wrong, this defensive layer would not catch it and could silently propagate a bad layout into
parseHeader/parseConfig/parseEngine/parseAccount.No currently-registered tier size actually violates the invariant — that's why this gap never surfaced as a test failure; it's a coverage gap in a defense-in-depth mechanism, not an active misparse.
Fix
Wrap every
buildLayout*(...)return value invalidateLayout(...)insidedetectSlabLayout, including both branches of the V1D/V2 disambiguation path.Test plan
test/slab.test.tsthat readsdetectSlabLayout's source and asserts everybuildLayout*call site is wrapped invalidateLayout(...)— the most direct way to verify the wiring exists, since no real registered tier size can currently trigger an actualvalidateLayoutthrow (by construction, everySLAB_TIERS_*entry was computed to satisfy the invariant).pnpm testexit 0, including "detectSlabLayout validateLayout coverage check passed!"); vitest portion unchanged at 851 passed / 31 skipped since the new test lives inslab.test.ts, run viatsxoutside the vitest-counted suite.