mirror of
https://github.com/nodejs/node.git
synced 2025-05-04 12:50:15 +00:00

Change the type of `Buffer::kMaxLength` to size_t because upcoming changes in V8 will allow typed arrays > 2 GB on 64 bits platforms. Not all platforms handle file reads and writes > 2 GB though so keep enforcing the 2 GB typed array limit for I/O operations. Fixes: https://github.com/nodejs/node/issues/31399 Refs: https://github.com/libuv/libuv/pull/1501 PR-URL: https://github.com/nodejs/node/pull/31406 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Shelley Vohr <codebytere@gmail.com>
44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
// Flags: --expose-internals
|
|
'use strict';
|
|
|
|
require('../common');
|
|
|
|
const assert = require('assert');
|
|
const { validateOffsetLengthWrite } = require('internal/fs/utils');
|
|
|
|
// Most platforms don't allow reads or writes >= 2 GB.
|
|
// See https://github.com/libuv/libuv/pull/1501.
|
|
const kIoMaxLength = 2 ** 31 - 1;
|
|
|
|
// RangeError when offset > byteLength
|
|
{
|
|
const offset = 100;
|
|
const length = 100;
|
|
const byteLength = 50;
|
|
assert.throws(
|
|
() => validateOffsetLengthWrite(offset, length, byteLength),
|
|
{
|
|
code: 'ERR_OUT_OF_RANGE',
|
|
name: 'RangeError',
|
|
message: 'The value of "offset" is out of range. ' +
|
|
`It must be <= ${byteLength}. Received ${offset}`
|
|
}
|
|
);
|
|
}
|
|
|
|
// RangeError when byteLength < kIoMaxLength, and length > byteLength - offset.
|
|
{
|
|
const offset = kIoMaxLength - 150;
|
|
const length = 200;
|
|
const byteLength = kIoMaxLength - 100;
|
|
assert.throws(
|
|
() => validateOffsetLengthWrite(offset, length, byteLength),
|
|
{
|
|
code: 'ERR_OUT_OF_RANGE',
|
|
name: 'RangeError',
|
|
message: 'The value of "length" is out of range. ' +
|
|
`It must be <= ${byteLength - offset}. Received ${length}`
|
|
}
|
|
);
|
|
}
|