From aec307536eeaff048572a773f3f63be9be7b90f7 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Wed, 1 Feb 2023 18:15:29 +0100 Subject: [PATCH] Add maxByteLength option to "read all bytes" algo This commit adds a `maxBytesLength` option to the "read all bytes" algorithm, that if set, results in an early abort of the algorithm if the resulting byte sequence exceeds the maximum specified byte sequence length during streaming. --- index.bs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/index.bs b/index.bs index 274f4a279..8a4f5d5e3 100644 --- a/index.bs +++ b/index.bs @@ -6809,20 +6809,23 @@ a chunk from a {{ReadableStreamDefaultReader}} |reader|, given a [=read re

To read all - bytes from a {{ReadableStreamDefaultReader}} |reader|, given |successSteps|, - which is an algorithm accepting a [=byte sequence=], and |failureSteps|, which is an algorithm - accepting a JavaScript value: [=read-loop=] given |reader|, a new [=byte sequence=], - |successSteps|, and |failureSteps|. + bytes from a {{ReadableStreamDefaultReader}} |reader|, given |maxByteLength|, which is an + optional number, |successSteps|, which is an algorithm accepting a [=byte sequence=], and + |failureSteps|, which is an algorithm accepting a JavaScript value: [=read-loop=] given |reader|, a + new [=byte sequence=], |maxByteLength|, |successSteps|, and |failureSteps|.

For the purposes of the above algorithm, to read-loop given |reader|, |bytes|, - |successSteps|, and |failureSteps|: + |maxBytesLength|, |successSteps|, and |failureSteps|: 1. Let |readRequest| be a new [=read request=] with the following [=struct/items=]: : [=read request/chunk steps=], given |chunk| :: 1. If |chunk| is not a {{Uint8Array}} object, call |failureSteps| with a {{TypeError}} and abort these steps. + 1. If |maxBytesLength| is defined, and |bytes|'s [=byte sequence/length=] + + [=byte sequence/length=] of the bytes represented by |chunk| is greater than + |maxBytesLength|, call |failureSteps| with a {{QuotaExceededError}} and abort these steps. 1. Append the bytes represented by |chunk| to |bytes|. 1. [=Read-loop=] given |reader|, |bytes|, |successSteps|, and |failureSteps|.

This recursion could potentially cause a stack overflow if implemented