Skip to content

Commit

Permalink
buffer: coerce extrema to int in blob.slice
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
aduh95 authored and targos committed Oct 4, 2024
1 parent 1240197 commit b1ebb0d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/internal/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const {
lazyDOMException,
} = require('internal/util');
const { inspect } = require('internal/util/inspect');
const { convertToInt } = require('internal/webidl');

const {
codes: {
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit b1ebb0d

Please sign in to comment.