Skip to content

Commit

Permalink
buffer: fix blob range error with many chunks
Browse files Browse the repository at this point in the history
PR-URL: #47320
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
  • Loading branch information
KhafraDev authored and RafaelGSS committed Apr 8, 2023
1 parent 863b4d9 commit 23a69d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/internal/blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ const {
CountQueuingStrategy,
} = require('internal/webstreams/queuingstrategies');

const { queueMicrotask } = require('internal/process/task_queues');

const kHandle = Symbol('kHandle');
const kType = Symbol('kType');
const kLength = Symbol('kLength');
Expand Down Expand Up @@ -284,7 +286,7 @@ class Blob {
}
if (buffer !== undefined)
buffers.push(buffer);
readNext();
queueMicrotask(() => readNext());
});
};
readNext();
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-blob.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,3 +315,16 @@ assert.throws(() => new Blob({}), {

delete Object.prototype.type;
}

(async () => {
// Refs: https://github.com/nodejs/node/issues/47301

const random = Buffer.alloc(256).fill('0');
const chunks = [];

for (let i = 0; i < random.length; i += 2) {
chunks.push(random.subarray(i, i + 2));
}

await new Blob(chunks).arrayBuffer();
})().then(common.mustCall());

0 comments on commit 23a69d9

Please sign in to comment.