From bf8afe76443388ec7d59e3bc1fda6c9ac32a4e11 Mon Sep 17 00:00:00 2001 From: Zhenwei Jin <109658203+kylo5aby@users.noreply.github.com> Date: Mon, 6 May 2024 20:45:31 +0800 Subject: [PATCH] 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 Reviewed-By: James M Snell --- lib/internal/blob.js | 2 -- .../pummel/test-blob-slice-with-large-size.js | 21 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 test/pummel/test-blob-slice-with-large-size.js diff --git a/lib/internal/blob.js b/lib/internal/blob.js index e2cf4ada95fb91..76ae58db85b9eb 100644 --- a/lib/internal/blob.js +++ b/lib/internal/blob.js @@ -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) { diff --git a/test/pummel/test-blob-slice-with-large-size.js b/test/pummel/test-blob-slice-with-large-size.js new file mode 100644 index 00000000000000..639c2217db79e3 --- /dev/null +++ b/test/pummel/test-blob-slice-with-large-size.js @@ -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'); +}