Skip to content

Commit b72ba31

Browse files
fix(Blob.prototype.stream): handle undefined chunkSize (#24900)
### What does this PR do? `blob.stream(undefined)` ### How did you verify your code works? Added a test --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent b92d2ed commit b72ba31

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/bun.js/webcore/Blob.zig

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,14 +1980,13 @@ pub fn getStream(
19801980
return cached;
19811981
}
19821982
var recommended_chunk_size: SizeType = 0;
1983-
var arguments_ = callframe.arguments_old(2);
1984-
var arguments = arguments_.ptr[0..arguments_.len];
1985-
if (arguments.len > 0) {
1986-
if (!arguments[0].isNumber() and !arguments[0].isUndefinedOrNull()) {
1983+
const recommended_chunk_size_value = callframe.argument(0);
1984+
if (!recommended_chunk_size_value.isUndefinedOrNull()) {
1985+
if (!recommended_chunk_size_value.isNumber()) {
19871986
return globalThis.throwInvalidArguments("chunkSize must be a number", .{});
19881987
}
19891988

1990-
recommended_chunk_size = @as(SizeType, @intCast(@max(0, @as(i52, @truncate(arguments[0].toInt64())))));
1989+
recommended_chunk_size = @intCast(@max(0, @as(i52, @truncate(recommended_chunk_size_value.toInt64()))));
19911990
}
19921991
const stream = try jsc.WebCore.ReadableStream.fromBlobCopyRef(
19931992
globalThis,

test/internal/ban-limits.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
" catch bun.outOfMemory()": 0,
55
"!= alloc.ptr": 0,
66
"!= allocator.ptr": 0,
7-
".arguments_old(": 265,
7+
".arguments_old(": 264,
88
".jsBoolean(false)": 0,
99
".jsBoolean(true)": 0,
1010
".stdDir()": 42,

test/js/web/streams/streams.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,14 @@ it("new Response(stream).blob() (direct)", async () => {
10591059
expect(await blob.text()).toBe('{"hello":true}');
10601060
});
10611061

1062+
it("Blob.stream(undefined) does not crash", () => {
1063+
var blob = new Blob(["abdefgh"]);
1064+
var stream = blob.stream(undefined);
1065+
expect(stream instanceof ReadableStream).toBeTrue();
1066+
stream = blob.stream(null);
1067+
expect(stream instanceof ReadableStream).toBeTrue();
1068+
});
1069+
10621070
it("Blob.stream() -> new Response(stream).text()", async () => {
10631071
var blob = new Blob(["abdefgh"]);
10641072
var stream = blob.stream();

0 commit comments

Comments
 (0)