fix: F-7 VM type guards for unchecked accessor calls#33
Merged
Conversation
R8 deferred F-7 ("~82 unchecked .asInt()/.asString()") pending compiler
analysis. Deep verification found 85/100+ calls already guarded, bitwise
opcodes don't exist, and OP_DIV/OP_MOD zero-checks are inside type
guards. Actual scope: 11 sites (1 unsafe + 10 defense-in-depth).
Changes:
- READ_CONSTANT_STRING macro: type-guarded constant pool string access
with bounds check, replaces 8 raw .asString() calls (V-VM-002)
- OP_ITER_NEXT: add isInt() guard before .asInt() — the only truly
unguarded accessor, returns garbage bits on type mismatch (V-VM-003)
- OP_POLYGLOT: add isDict() guard before .asDictConst() on constant
pool block info dict (V-VM-004)
- OP_CLOSURE: add isVMClosure() guard before .asVMClosure() on
constant pool closure (V-VM-005)
Lines 3087/3231 (OP_IMPORT/OP_IMPORT_NAME) also gain bounds checking
by switching from direct constants[arg] to READ_CONSTANT_STRING.
Verified: build 0 errors, 396/396 tests, 738/738 leak checks,
100/100 fuzz cases, naab-x1 exit 0.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
NAAb Governance Report
All governance checks passed! Generated by NAAb Governance Engine v4.0 |
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.
Summary
Closes the last deferred finding from R8 audit — F-7: unchecked
.asInt()/.asString()/.asDictConst()/.asVMClosure()calls in vm.cpp.Deep analysis reduced the original estimate of ~82 unsafe sites to 11 actual unguarded accessors (the rest were already guarded by inline type checks):
.asString()calls → newREAD_CONSTANT_STRINGmacro with type + bounds checking.asInt()in OP_ITER_NEXT →isInt()guard (crash on non-int index = stack corruption).asDictConst()in OP_POLYGLOT →isDict()guard (defense-in-depth).asVMClosure()in OP_CLOSURE →isVMClosure()guard (defense-in-depth)Error messages use "Internal error" prefix (not "Type error") — these indicate VM/compiler bugs, not user code errors.
Changes
src/vm/vm.cpp: +37/-9 lines —READ_CONSTANT_STRINGmacro + 3 inline type guardsTest plan
cmake .. && make naab-lang -j4— 0 errors, 0 warningsbash run-all-tests.sh— 396/396 accounted, 0 unexpected failuresbash tests/security/test_error_msg_leaks.sh— 738+ passed, 0 failuresbash tests/security/test_govern_json_fuzz.sh— 100/100, 0 crashescd ~/naab-x1 && naab src/main.naab— exit 0for x in [1,2,3] { print(x) }— works🤖 Generated with Claude Code