Skip to content

Fix set buffer overflow#20

Merged
cs01 merged 6 commits intomainfrom
fix-set-buffer-overflow
Feb 19, 2026
Merged

Fix set buffer overflow#20
cs01 merged 6 commits intomainfrom
fix-set-buffer-overflow

Conversation

@cs01
Copy link
Owner

@cs01 cs01 commented Feb 19, 2026

Fix Set buffer overflow with dedup and dynamic reallocation

Both Set<number> and Set<string> had a fixed 4-element buffer with no capacity check or reallocation. Adding more than 4 elements wrote past the buffer — silent corruption on x86_64, immediate crash on ARM64. This was the root cause of the macOS CI failures when compiling JSON.parse<T>() (the generatedStructs Set accumulated 6+ entries).

Changes

  • set.tsgenerateSetAdd and generateStringSetAdd now do:
    • Duplicate check before insert (linear scan with fcmp oeq / strcmp)
    • Capacity check (size == capacity)
    • Dynamic reallocation when full (double capacity, GC_malloc, memcpy)
  • New test fixturesset-overflow.ts (10 numeric elements), string-set-overflow.ts (8 string elements), nested-interface-access.ts, string-concat-assign.ts
  • CI — Added self-hosting tests to the Linux glibc job (was only on musl and macOS)

Test plan

  • npm test — 288 pass, 0 fail
  • npm run verify:quick — self-hosting passes

@cs01 cs01 merged commit 348c3e4 into main Feb 19, 2026
13 checks passed
@cs01 cs01 deleted the fix-set-buffer-overflow branch February 19, 2026 22:33
cs01 added a commit that referenced this pull request Feb 20, 2026
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

Comments