Skip to content

Commit fcc25f9

Browse files
mscdexBridgeAR
authored andcommitted
buffer: fix writeUInt16BE range check
Fixes: #24205 PR-URL: #24208 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 1242981 commit fcc25f9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/internal/buffer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ function writeU_Int16BE(buf, value, offset, min, max) {
667667
}
668668

669669
function writeUInt16BE(value, offset = 0) {
670-
return writeU_Int16BE(this, value, offset, 0, 0xffffffff);
670+
return writeU_Int16BE(this, value, offset, 0, 0xffff);
671671
}
672672

673673
function writeIntLE(value, offset, byteLength) {

test/parallel/test-buffer-writeuint.js

+12
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ const assert = require('assert');
8484

8585
data.writeUInt16BE(value, 0);
8686
assert.ok(data.equals(new Uint8Array([0xff, 0x80, 0x43, 0x23])));
87+
88+
value = 0xfffff;
89+
['writeUInt16BE', 'writeUInt16LE'].forEach((fn) => {
90+
assert.throws(
91+
() => data[fn](value, 0),
92+
{
93+
code: 'ERR_OUT_OF_RANGE',
94+
message: 'The value of "value" is out of range. ' +
95+
`It must be >= 0 and <= 65535. Received ${value}`
96+
}
97+
);
98+
});
8799
}
88100

89101
// Test 32 bit

0 commit comments

Comments
 (0)