`Array.prototype.indexOf` / `includes` search elements appended while converting `fromIndex`
Maintainers usually reply within 5 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 69/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- c, javascript
Research direction
The affected functions are js_array_indexOf and js_array_includes in quickjs.c. Read how each fast-array loop uses count after JS_ToInt64Clamp converts fromIndex, then run the provided JavaScript examples with ./qjs; done means both return the expected -1 and false when conversion appends a matching element.
Written by the indexing model from the issue text.
Description
Array.prototype.indexOf and Array.prototype.includes search elements appended to a fast array while converting fromIndex, instead of stopping at the length read before fromIndex conversion.
// t.js
var a = [4, 2, null];
console.log(a.indexOf(1.25, { valueOf() { a.push(1.25); return 0; } }));
var b = [4, 2, null];
console.log(b.includes(1.25, { valueOf() { b.push(1.25); return 0; } }));
Running ./qjs t.js prints:
3
true
Expected (Node.js v26.13.0; Array.prototype.indexOf):
-1
false
In js_array_indexOf and js_array_includes (quickjs.c), len is read before JS_ToInt64Clamp converts argv[1], and the slow-path loop stops at n < len, but the fast-array loop after js_get_fast_array(ctx, obj, &arrp, &count) iterates for (; n < count; n++) without clamping count to len.
Versions: QuickJS master 2519774 (2026-11-23) and release 2026-06-04 (3d5e064), Linux x86_64.
Credit: https://ucsbplse.github.io/
- Dominant language
- C
- Stars
- 11.1k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bellard/quickjs
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 5 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 5 days
-
`ArrayBuffer.prototype.transfer(n)` with n > maxByteLength throws TypeError instead of RangeErrorOpen
Difficulty 1/5 Under an hour Newbie friendliness 82/100
Maintainers usually reply within 5 days
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
Maintainers usually reply within 5 days
-
Difficulty 3/5 1-2 days Newbie friendliness 70/100
Maintainers usually reply within 5 days
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
bug severity: medium
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
AlessandroSangiuliano/Uros#1014 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
OpenXiangShan/NEMU#1314 ·
Maintainers usually reply within 1 day
-
`get_options()` repeats the first byte when hex-encoding octet stringsPossibly taken @rue19 claimed this today. Open
Difficulty 1/5 Under an hour Newbie friendliness 85/100
OpenPrinting/cups#1830 ·
Maintainers usually reply within 1 day