Merged
Conversation
Fixed 4 HIGH priority undefined behavior issues from Phase 117 action plan:
1. INTEGER OVERFLOW - For-Loop Edge Case (lvm_loops.cpp:92)
- Added explicit handling for LUA_MININTEGER in descending for-loops
- Prevents potential undefined behavior in step division
- Uses l_unlikely() for branch prediction optimization
2. SIZE CALCULATION OVERFLOW - Safe Multiplication (llimits.h, ltable.cpp)
- Added safe multiplication helpers: wouldMultiplyOverflow(), safeMul()
- Applied to concretesize() table array allocation (ltable.cpp:681-682)
- Returns 0 on overflow to trigger allocation failure path
- Prevents heap corruption from undersized allocations
3. STACK OPERATION BOUNDS CHECKS (lvm.cpp, ldo.cpp)
- Added defensive assertions in VM hot paths:
* OP_EQ case: verify stack not empty before access (lvm.cpp:177)
* OP_CONCAT case: verify top-2 valid, range safe (lvm.cpp:188-189)
* retHook: verify nres within bounds (ldo.cpp:395)
* tryFuncTM: verify func pointer valid (ldo.cpp:430)
* genMoveResults: verify nres and pointers valid (ldo.cpp:445, 450)
- Debug-mode protection against out-of-bounds access
4. SHIFT OPERATION VALIDATION (lobject.h, lstrlib.cpp)
- Added bit parameter validation in GCObject bit manipulation:
* setMarkedBit/clearMarkedBit: assert 0 <= bit < 8 (lobject.h:244, 248)
- Added size validation in string packing:
* b_pack Kint/Kuint: assert size > 0 before shift (lstrlib.cpp:1634, 1644)
- Prevents undefined behavior from out-of-range shifts
TESTING:
- All 30+ test files pass: "final OK !!!"
- Performance: 4.18s average (4.00s-4.40s range)
- Target: ≤4.33s ✅
- Result: Better than 4.20s baseline! (10% improvement from 4.48s initial)
DELIVERABLES:
- Safe arithmetic library (wouldMultiplyOverflow, safeMul)
- Comprehensive bounds-safe assertions (5 locations)
- Parameter validation for bit operations (4 locations)
- Zero performance regression (actually improved!)
Status: Phase 117 complete, 4/4 high-priority issues fixed
Next: Phase 118 (Medium Priority & Hardening)
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.
Fixed 4 HIGH priority undefined behavior issues from Phase 117 action plan:
INTEGER OVERFLOW - For-Loop Edge Case (lvm_loops.cpp:92)
SIZE CALCULATION OVERFLOW - Safe Multiplication (llimits.h, ltable.cpp)
STACK OPERATION BOUNDS CHECKS (lvm.cpp, ldo.cpp)
SHIFT OPERATION VALIDATION (lobject.h, lstrlib.cpp)
TESTING:
DELIVERABLES:
Status: Phase 117 complete, 4/4 high-priority issues fixed
Next: Phase 118 (Medium Priority & Hardening)