GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib,test: do not hardcode Buffer.kMaxLength · nodejs/node@5bca8fe

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/internal
    • blob.js
  • test/parallel
    • test-blob-buffer-too-large.js
    • test-buffer-alloc.js
    • test-buffer-over-max-length.js
    • test-buffer-tostring-rangeerror.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/internal/blob.js‎

Copy file name to clipboardExpand all lines: lib/internal/blob.js
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ const {
2424
concat,
2525
getDataObject,
2626
} = internalBinding('blob');
27+
const {
28+
kMaxLength,
29+
} = internalBinding('buffer');
2730

2831
const {
2932
TextDecoder,
@@ -62,7 +65,6 @@ const {
6265
} = require('internal/errors');
6366

6467
const {
65-
isUint32,
6668
validateDictionary,
6769
} = require('internal/validators');
6870

@@ -158,8 +160,8 @@ class Blob {
158160
return src;
159161
});
160162

161-
if (!isUint32(length))
162-
throw new ERR_BUFFER_TOO_LARGE(0xFFFFFFFF);
163+
if (length > kMaxLength)
164+
throw new ERR_BUFFER_TOO_LARGE(kMaxLength);
163165

164166
this[kHandle] = _createBlob(sources_, length);
165167
this[kLength] = length;
Collapse file

‎test/parallel/test-blob-buffer-too-large.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-blob-buffer-too-large.js
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33

44
const common = require('../common');
55
const assert = require('assert');
6-
const { Blob } = require('buffer');
6+
const { Blob, kMaxLength } = require('buffer');
77

88
if (common.isFreeBSD)
99
common.skip('Oversized buffer make the FreeBSD CI runner crash');
1010

1111
try {
12-
new Blob([new Uint8Array(0xffffffff), [1]]);
12+
new Blob([new Uint8Array(kMaxLength), [1]]);
1313
} catch (e) {
1414
if (
1515
e.message === 'Array buffer allocation failed' ||
16-
e.message === 'Invalid typed array length: 4294967295'
16+
e.message === `Invalid typed array length: ${kMaxLength}`
1717
) {
1818
common.skip(
1919
'Insufficient memory on this platform for oversized buffer test.'
Collapse file

‎test/parallel/test-buffer-alloc.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-buffer-alloc.js
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ const common = require('../common');
44
const assert = require('assert');
55
const vm = require('vm');
66

7-
const SlowBuffer = require('buffer').SlowBuffer;
7+
const {
8+
SlowBuffer,
9+
kMaxLength,
10+
} = require('buffer');
811

912
// Verify the maximum Uint8Array size. There is no concrete limit by spec. The
1013
// internal limits should be updated if this fails.
1114
assert.throws(
12-
() => new Uint8Array(2 ** 32 + 1),
13-
{ message: 'Invalid typed array length: 4294967297' }
15+
() => new Uint8Array(kMaxLength + 1),
16+
{ message: `Invalid typed array length: ${kMaxLength + 1}` },
1417
);
1518

1619
const b = Buffer.allocUnsafe(1024);
Collapse file

‎test/parallel/test-buffer-over-max-length.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-buffer-over-max-length.js
-10Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,8 @@ const bufferMaxSizeMsg = {
1212
name: 'RangeError',
1313
};
1414

15-
assert.throws(() => Buffer((-1 >>> 0) + 2), bufferMaxSizeMsg);
16-
assert.throws(() => SlowBuffer((-1 >>> 0) + 2), bufferMaxSizeMsg);
17-
assert.throws(() => Buffer.alloc((-1 >>> 0) + 2), bufferMaxSizeMsg);
18-
assert.throws(() => Buffer.allocUnsafe((-1 >>> 0) + 2), bufferMaxSizeMsg);
19-
assert.throws(() => Buffer.allocUnsafeSlow((-1 >>> 0) + 2), bufferMaxSizeMsg);
20-
2115
assert.throws(() => Buffer(kMaxLength + 1), bufferMaxSizeMsg);
2216
assert.throws(() => SlowBuffer(kMaxLength + 1), bufferMaxSizeMsg);
2317
assert.throws(() => Buffer.alloc(kMaxLength + 1), bufferMaxSizeMsg);
2418
assert.throws(() => Buffer.allocUnsafe(kMaxLength + 1), bufferMaxSizeMsg);
2519
assert.throws(() => Buffer.allocUnsafeSlow(kMaxLength + 1), bufferMaxSizeMsg);
26-
27-
// issue GH-4331
28-
assert.throws(() => Buffer.allocUnsafe(0x100000001), bufferMaxSizeMsg);
29-
assert.throws(() => Buffer.allocUnsafe(0xFFFFFFFFF), bufferMaxSizeMsg);
Collapse file

‎test/parallel/test-buffer-tostring-rangeerror.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-buffer-tostring-rangeerror.js
+11-6Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
'use strict';
22
require('../common');
33

4-
// This test ensures that Node.js throws a RangeError when trying to convert a
5-
// gigantic buffer into a string.
4+
// This test ensures that Node.js throws an Error when trying to convert a
5+
// large buffer into a string.
66
// Regression test for https://github.com/nodejs/node/issues/649.
77

88
const assert = require('assert');
9-
const SlowBuffer = require('buffer').SlowBuffer;
9+
const {
10+
SlowBuffer,
11+
constants: {
12+
MAX_STRING_LENGTH,
13+
},
14+
} = require('buffer');
1015

11-
const len = 1422561062959;
16+
const len = MAX_STRING_LENGTH + 1;
1217
const message = {
13-
code: 'ERR_OUT_OF_RANGE',
14-
name: 'RangeError',
18+
code: 'ERR_STRING_TOO_LONG',
19+
name: 'Error',
1520
};
1621
assert.throws(() => Buffer(len).toString('utf8'), message);
1722
assert.throws(() => SlowBuffer(len).toString('utf8'), message);

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.