Skip to content
Permalink
Browse files

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>
  • Loading branch information
mscdex authored and Trott committed Nov 13, 2019
1 parent 48cadcb commit c14c476614e3134867ddb997bdfe5a41ba668175
Showing with 3 additions and 3 deletions.
  1. +1 −1 lib/internal/buffer.js
  2. +1 −1 test/parallel/test-buffer-writeint.js
  3. +1 −1 test/parallel/test-buffer-writeuint.js
@@ -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)
@@ -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;
@@ -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_') :

0 comments on commit c14c476

Please sign in to comment.
You can’t perform that action at this time.