vm.c: make stack_extend_alloc cover the frame offset - #7305
Conversation
Commit 16baea0 changed the stack size floor from the frame base offset to the remaining capacity, stend - ci->stack. While ci->stack is within stbase..stend the floor never fires. When ci->stack sits past stend the unsigned subtraction wraps around and the VM raises NoMemoryError instead of growing the stack. Restore the frame base offset from the stack bottom. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
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 (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthrough
ChangesStack growth allocation
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This is a localized stack-growth correction, and no actionable merge-blocking risk remains after normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
Problem
In
stack_extend_alloc(), commit 16baea0 changed the stack size floor calculation from the frame base offset to the remaining capacity:Impact
This reversal causes two issues depending on
ci->stack:ci->stackis withinstbase..stend, the calculated value never exceeds the old size, rendering the floor calculation useless.ci->stacksits paststend(e.g., when an embedder enters the VM with an undersized context, as previously seen in mruby-task: fix VM stack overflow when a larger proc is set on an existing task #7279), the unsigned subtraction wraps around to a huge value. This poisons the growth math, raising aNoMemoryErrorinstead of properly growing the stack.Fix
Restore the pre-refactor logic. The floor must be the frame base offset from the stack bottom (
mrb->c->ci->stack - oldbase).An assertion on
ci->stack <= stendwould not be a substitute. Asserts compile out in release builds and the wrap-around would remain there.Summary by CodeRabbit