Skip to content

Commit

Permalink
buffer: fix 6-byte writeUIntBE() range check
Browse files Browse the repository at this point in the history
Fixes: #30420

PR-URL: #30459
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
mscdex authored and Trott committed Nov 30, 2019
1 parent 48cadcb commit c14c476
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/internal/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ function writeUInt8(value, offset = 0) {

function writeUIntBE(value, offset, byteLength) {
if (byteLength === 6)
return writeU_Int48BE(this, value, offset, 0, 0xffffffffffffff);
return writeU_Int48BE(this, value, offset, 0, 0xffffffffffff);
if (byteLength === 5)
return writeU_Int40BE(this, value, offset, 0, 0xffffffffff);
if (byteLength === 3)
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-buffer-writeint.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ const errorOutOfBounds = common.expectsError({
});

// Test 1 to 6 bytes.
for (let i = 1; i < 6; i++) {
for (let i = 1; i <= 6; i++) {
['writeIntBE', 'writeIntLE'].forEach((fn) => {
const min = -(2 ** (i * 8 - 1));
const max = 2 ** (i * 8 - 1) - 1;
Expand Down
2 changes: 1 addition & 1 deletion test/parallel/test-buffer-writeuint.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ const assert = require('assert');
});

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

0 comments on commit c14c476

Please sign in to comment.