Skip to content

fix: resolve negative fromindex in array indexof to prevent oob access (#265)#265

Merged
cs01 merged 1 commit intomainfrom
fix/indexof-negative-fromindex
Mar 12, 2026
Merged

fix: resolve negative fromindex in array indexof to prevent oob access (#265)#265
cs01 merged 1 commit intomainfrom
fix/indexof-negative-fromindex

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Mar 12, 2026

Summary

  • arr.indexOf(val, -N) with negative fromIndex was using the raw negative value as the loop start index, causing out-of-bounds memory access via GEP with negative index
  • Fix resolves negative indices as max(0, length + index) per JS spec, in both numeric and string array indexOf paths
  • Affected two separate code paths: search.ts (numeric arrays) and string-methods.ts (string arrays dispatched via string-dispatch.ts)

Test plan

  • npm run verify:quick passes (tests + Stage 1 self-hosting)
  • New test: arrays/indexof-negative-fromindex.ts covers both number[] and string[] with negative, zero, positive, and very-negative fromIndex values

🤖 Generated with Claude Code

@cs01 cs01 merged commit c8155a6 into main Mar 12, 2026
12 checks passed
@cs01 cs01 deleted the fix/indexof-negative-fromindex branch March 12, 2026 03:32
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