buffer: remove lines setting indexes to integer value

PR-URL: https://github.com/nodejs/node/pull/52588
Refs: https://github.com/nodejs/node/issues/52585
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Zhenwei Jin 2024-05-06 20:45:31 +08:00 committed by GitHub
parent b1b0233cb2
commit bf8afe7644
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 2 deletions

View File

@ -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) {

View File

@ -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');
}