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 <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>
  • Loading branch information
mscdex authored and targos committed Dec 5, 2019
1 parent 053c179 commit f0d4392
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
Expand Up @@ -736,7 +736,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
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
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 f0d4392

Please sign in to comment.