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 targos committed May 8, 2024
1 parent 15aad62 commit f1bc994
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 @@ -243,14 +243,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 f1bc994

Please sign in to comment.