Skip to content

Commit 63eb4fe

Browse files
mscdexaddaleax
authored andcommitted
buffer: fix 6-byte writeUIntBE() range check
Fixes: #30420 PR-URL: #30459 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent f37450f commit 63eb4fe

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

lib/internal/buffer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ function writeUInt8(value, offset = 0) {
736736

737737
function writeUIntBE(value, offset, byteLength) {
738738
if (byteLength === 6)
739-
return writeU_Int48BE(this, value, offset, 0, 0xffffffffffffff);
739+
return writeU_Int48BE(this, value, offset, 0, 0xffffffffffff);
740740
if (byteLength === 5)
741741
return writeU_Int40BE(this, value, offset, 0, 0xffffffffff);
742742
if (byteLength === 3)

test/parallel/test-buffer-writeint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ const errorOutOfBounds = common.expectsError({
213213
});
214214

215215
// Test 1 to 6 bytes.
216-
for (let i = 1; i < 6; i++) {
216+
for (let i = 1; i <= 6; i++) {
217217
['writeIntBE', 'writeIntLE'].forEach((fn) => {
218218
const min = -(2 ** (i * 8 - 1));
219219
const max = 2 ** (i * 8 - 1) - 1;

test/parallel/test-buffer-writeuint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ const assert = require('assert');
170170
});
171171

172172
// Test 1 to 6 bytes.
173-
for (let i = 1; i < 6; i++) {
173+
for (let i = 1; i <= 6; i++) {
174174
const range = i < 5 ? `= ${val - 1}` : ` 2 ** ${i * 8}`;
175175
const received = i > 4 ?
176176
String(val).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1_') :

0 commit comments

Comments
 (0)