Skip to content

Commit 4062b3f

Browse files
authored
buffer: coerce extrema to int in blob.slice
PR-URL: #55141 Fixes: #55139 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent e973c3e commit 4062b3f

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/internal/blob.js

+7
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const {
5454
lazyDOMException,
5555
} = require('internal/util');
5656
const { inspect } = require('internal/util/inspect');
57+
const { convertToInt } = require('internal/webidl');
5758

5859
const {
5960
codes: {
@@ -239,6 +240,12 @@ class Blob {
239240
slice(start = 0, end = this[kLength], contentType = '') {
240241
if (!isBlob(this))
241242
throw new ERR_INVALID_THIS('Blob');
243+
244+
// Coerce values to int
245+
const opts = { __proto__: null, signed: true };
246+
start = convertToInt('start', start, 64, opts);
247+
end = convertToInt('end', end, 64, opts);
248+
242249
if (start < 0) {
243250
start = MathMax(this[kLength] + start, 0);
244251
} else {

test/parallel/test-blob.js

+1
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ assert.throws(() => new Blob({}), {
483483

484484
assert.ok(blob.slice(0, 1).constructor === Blob);
485485
assert.ok(blob.slice(0, 1) instanceof Blob);
486+
assert.ok(blob.slice(0, 1.5) instanceof Blob);
486487
}
487488

488489
(async () => {

0 commit comments

Comments
 (0)