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
This commit is contained in:
Matthew Gaudet 2022-03-31 16:00:59 +00:00
Родитель 06cfe278af
Коммит db4cebaf5f
1 изменённых файлов: 4 добавлений и 3 удалений

Просмотреть файл

@ -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 the stack, 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();