From 0cd61ceb2e77efb0f83c893baf67e8ab06842265 Mon Sep 17 00:00:00 2001 From: Jason Zhang Date: Fri, 29 Nov 2024 14:01:42 +1030 Subject: [PATCH] stream: validate undefined sizeAlgorithm in WritableStream --- lib/internal/webstreams/writablestream.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/internal/webstreams/writablestream.js b/lib/internal/webstreams/writablestream.js index 5baaf20c30ba26..03b48dd043bc41 100644 --- a/lib/internal/webstreams/writablestream.js +++ b/lib/internal/webstreams/writablestream.js @@ -1176,9 +1176,18 @@ function writableStreamDefaultControllerGetDesiredSize(controller) { } function writableStreamDefaultControllerGetChunkSize(controller, chunk) { + const { + stream, + sizeAlgorithm, + } = controller[kState]; + if (sizeAlgorithm === undefined) { + assert(stream[kState].state === 'errored' || stream[kState].state === 'erroring'); + return 1; + } + try { return FunctionPrototypeCall( - controller[kState].sizeAlgorithm, + sizeAlgorithm, undefined, chunk); } catch (error) {