`ArrayBuffer.prototype.transfer(n)` with n > maxByteLength throws TypeError instead of RangeError

Open Beginner friendly
#630 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 5 days

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
c, javascript
Domain
backend

Research direction

In quickjs.c, inspect js_array_buffer_transfer and the resizable buffer check for new_len > max_len. Compare its error with the RangeError from resize and the AllocateArrayBuffer behavior cited in the issue. Reproduce with the provided t.js snippet using ./qjs; done means transfer(9) throws RangeError when maxByteLength is 5.

Written by the indexing model from the issue text.

Description

Calling ArrayBuffer.prototype.transfer(newLength) on a resizable ArrayBuffer with newLength > maxByteLength throws TypeError instead of RangeError.

// t.js
var b = new ArrayBuffer(2, { maxByteLength: 5 });
try { b.transfer(9); } catch (e) { console.log(e.name + ": " + e.message); }
try { b.resize(9); } catch (e) { console.log(e.name + ": " + e.message); }

Running ./qjs t.js prints:

TypeError: invalid array buffer length
RangeError: invalid array buffer length

Expected (Node.js v26.13.0; AllocateArrayBuffer): both throw RangeError (transfer preserves resizability and allocates the target buffer with byteLength = 9 and maxByteLength = 5).

In js_array_buffer_transfer (quickjs.c), the new_len > max_len check for resizable buffers calls JS_ThrowTypeError(ctx, "invalid array buffer length") instead of JS_ThrowRangeError.

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bellard/quickjs

All issues in bellard/quickjs

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.