Skip to content

fix: use zext instead of sext for map/splice size calculations#285

Merged
cs01 merged 1 commit intomainfrom
fix/capacity-overflow
Mar 12, 2026
Merged

fix: use zext instead of sext for map/splice size calculations#285
cs01 merged 1 commit intomainfrom
fix/capacity-overflow

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 12, 2026

Summary

  • Replace sext i32 to i64 with zext i32 to i64 for size/capacity values in map and splice codegen
  • sext on a large unsigned i32 (e.g., capacity after shl i32 cap, 1) sign-extends to a negative i64, causing massive or negative allocation sizes in GC_malloc
  • Affected: 9 locations in map.ts (mapSize, capacity extensions), 4 in splice.ts (deleteCount, elemsAfter)
  • Same class of bug as PR fix: prevent i32 overflow in array/string copy size calculations #268 (which fixed array/string copy size calculations)

Test plan

  • npm run verify:quick passes (tests + Stage 1 self-hosting)

🤖 Generated with Claude Code

@cs01 cs01 merged commit 660b148 into main Mar 12, 2026
17 of 18 checks passed
@cs01 cs01 deleted the fix/capacity-overflow branch March 12, 2026 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant