Skip to content

Commit

Permalink
buffer: remove lines setting indexes to integer value
Browse files Browse the repository at this point in the history
PR-URL: #52588
Refs: #52585
Reviewed-By: Antoine du Hamel <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
kylo5aby authored and marco-ippolito committed Jun 17, 2024
1 parent 1dce5de commit 16ae2b2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 0 additions & 2 deletions lib/internal/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,12 @@ class Blob {
} else {
start = MathMin(start, this[kLength]);
}
start |= 0;

if (end < 0) {
end = MathMax(this[kLength] + end, 0);
} else {
end = MathMin(end, this[kLength]);
}
end |= 0;

contentType = `${contentType}`;
if (RegExpPrototypeExec(disallowedTypeCharacters, contentType) !== null) {
Expand Down
21 changes: 21 additions & 0 deletions test/pummel/test-blob-slice-with-large-size.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';
const common = require('../common');

// Buffer with size > INT32_MAX
common.skipIf32Bits();

const assert = require('assert');

const size = 2 ** 31;

try {
const buf = Buffer.allocUnsafe(size);
const blob = new Blob([buf]);
const slicedBlob = blob.slice(size - 1, size);
assert.strictEqual(slicedBlob.size, 1);
} catch (e) {
if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED') {
throw e;
}
common.skip('insufficient space for Buffer.allocUnsafe');
}

0 comments on commit 16ae2b2

Please sign in to comment.