0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00

buffer: coerce extrema to int in blob.slice

PR-URL: https://github.com/nodejs/node/pull/55141
Fixes: https://github.com/nodejs/node/issues/55139
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Antoine du Hamel 2024-09-29 11:51:10 +02:00 committed by GitHub
parent e973c3e94b
commit 4062b3fb43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 0 deletions

View File

@ -54,6 +54,7 @@ const {
lazyDOMException,
} = require('internal/util');
const { inspect } = require('internal/util/inspect');
const { convertToInt } = require('internal/webidl');
const {
codes: {
@ -239,6 +240,12 @@ class Blob {
slice(start = 0, end = this[kLength], contentType = '') {
if (!isBlob(this))
throw new ERR_INVALID_THIS('Blob');
// Coerce values to int
const opts = { __proto__: null, signed: true };
start = convertToInt('start', start, 64, opts);
end = convertToInt('end', end, 64, opts);
if (start < 0) {
start = MathMax(this[kLength] + start, 0);
} else {

View File

@ -483,6 +483,7 @@ assert.throws(() => new Blob({}), {
assert.ok(blob.slice(0, 1).constructor === Blob);
assert.ok(blob.slice(0, 1) instanceof Blob);
assert.ok(blob.slice(0, 1.5) instanceof Blob);
}
(async () => {