From 21377df70d8bc50ab5de790172fa4a6253a237cc Mon Sep 17 00:00:00 2001 From: Matthew Gaudet Date: Tue, 5 Apr 2022 19:15:26 +0000 Subject: [PATCH] Bug 1761483 - Limit chunk size in stream to avoid un-necessary OOM r=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 --- dom/base/BodyStream.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dom/base/BodyStream.cpp b/dom/base/BodyStream.cpp index 4d055f2e48023..caf9c0245f4ea 100644 --- a/dom/base/BodyStream.cpp +++ b/dom/base/BodyStream.cpp @@ -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(UINT32_MAX), aAvailableData); + std::min(static_cast(256 * 1024 * 1024), aAvailableData); // Create Chunk aRv.MightThrowJSException();