GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — buffer: fix out of range for toString · nodejs/node@1fb67af

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • buffer.js
  • test/parallel
    • test-buffer-tostring-range.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/buffer.js‎

Copy file name to clipboardExpand all lines: lib/buffer.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,12 +843,12 @@ Buffer.prototype.toString = function toString(encoding, start, end) {
843843
else if (start >= len)
844844
return '';
845845
else
846-
start |= 0;
846+
start = MathTrunc(start) || 0;
847847

848848
if (end === undefined || end > len)
849849
end = len;
850850
else
851-
end |= 0;
851+
end = MathTrunc(end) || 0;
852852

853853
if (end <= start)
854854
return '';
Collapse file

‎test/parallel/test-buffer-tostring-range.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-buffer-tostring-range.js
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
require('../common');
3+
const common = require('../common');
44
const assert = require('assert');
55

66
const rangeBuffer = Buffer.from('abc');
@@ -98,3 +98,11 @@ assert.throws(() => {
9898
name: 'TypeError',
9999
message: 'Unknown encoding: null'
100100
});
101+
102+
// Must not throw when start and end are within kMaxLength
103+
// Cannot test on 32bit machine as we are testing the case
104+
// when start and end are above the threshold
105+
common.skipIf32Bits();
106+
const threshold = 0xFFFFFFFF;
107+
const largeBuffer = Buffer.alloc(threshold + 20);
108+
largeBuffer.toString('utf8', threshold, threshold + 20);

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.