Skip to content

fs.read offset and length can only be up to 0x7FFFFFFF (max int32 instead of uint32) #26563

Closed
@zbjornson

Description

@zbjornson
  • Version: v10.15.0
  • Platform: Win64, Linux (all)
  • Subsystem: fs
const fs = require("fs");
const dest = new Uint16Array(1073741824);
// dest.byteLength > buffer.kMaxLength
const fd = fs.openSync("./temp.dat", "r");
fs.readSync(fd, dest, 0, dest.byteLength, 0);

throws

RangeError [ERR_OUT_OF_RANGE]: The value of "length" is out of range. It must be >= 0 && <= 2147483648. Received -2147483648

That's because length |= 0 here converts to signed int32.

Since the max TypedArray size in v8 is expanding to MAX_SAFE_INTEGER, switching to Math.round() I think makes sense (vs adding >>> 0, which would only support uint32)? Happy to open a PR if agreed.

(#21994 looks slightly related, but is about bigint position values.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bufferIssues and PRs related to the buffer subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions