Skip to content

Commit

Permalink
Bug 1761483 - Limit chunk size in stream to avoid un-necessary OOM r=…
Browse files Browse the repository at this point in the history
…smaug

Discovered that Windows 32-bit was having trouble with the test case on the bug,
and figured that it might be preferable to limit chunk size to something more
constrained.

Differential Revision: https://phabricator.services.mozilla.com/D142512
  • Loading branch information
mgaudet committed Apr 5, 2022
1 parent 6ec91fd commit 21377df
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions dom/base/BodyStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,11 @@ void BodyStream::EnqueueChunkWithSizeIntoStream(JSContext* aCx,
ReadableStream* aStream,
uint64_t aAvailableData,
ErrorResult& aRv) {
// Because nsIInputStream can only read UINT32_MAX bytes in one go, limit
// ourselves to that for chunk size.
// To avoid OOMing up on huge amounts of available data on a 32 bit system,
// as well as potentially overflowing nsIInputStream's Read method's
// parameter, let's limit our maximum chunk size to 256MB.
uint32_t ableToRead =
std::min(static_cast<uint64_t>(UINT32_MAX), aAvailableData);
std::min(static_cast<uint64_t>(256 * 1024 * 1024), aAvailableData);

// Create Chunk
aRv.MightThrowJSException();
Expand Down

0 comments on commit 21377df

Please sign in to comment.