Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9a64cec

Browse filesBrowse files
mscdexMylesBorins
authored andcommitted
buffer: fix writeUInt16BE range check
Fixes: #24205 PR-URL: #24208 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent d7a3a3b commit 9a64cec
Copy full SHA for 9a64cec

File tree

Expand file treeCollapse file tree

2 files changed

+13
-1
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-1
lines changed
Open diff view settings
Collapse file

‎lib/internal/buffer.js‎

Copy file name to clipboardExpand all lines: lib/internal/buffer.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ function writeU_Int16BE(buf, value, offset, min, max) {
658658
}
659659

660660
function writeUInt16BE(value, offset = 0) {
661-
return writeU_Int16BE(this, value, offset, 0, 0xffffffff);
661+
return writeU_Int16BE(this, value, offset, 0, 0xffff);
662662
}
663663

664664
function writeIntLE(value, offset = 0, byteLength) {
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-buffer-writeuint.js
+12Lines changed: 12 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.