Skip to content

Commit

Permalink
NotReadableError: The I/O read operation failed for large files of si…
Browse files Browse the repository at this point in the history
…ze 4G+

https://bugs.webkit.org/show_bug.cgi?id=272600
rdar://126863800

Reviewed by Alex Christensen.

FileReaderLoader is limiting the size of data that can be read.
This restriction is not needed when reading data via a ReadableStream.
We stop allocating a buffer in FileReaderLoader for ReadType::ReadAsBinaryChunks as this is unnecessary.
Instead, we let the client store the buffers.

Manually tested for big files.

* Source/WebCore/fileapi/FileReaderLoader.cpp:
(WebCore::FileReaderLoader::didReceiveResponse):
* Source/WebCore/fileapi/FileReaderLoader.h:

Canonical link: https://commits.webkit.org/278457@main
  • Loading branch information
youennf committed May 7, 2024
1 parent 48d82b1 commit 0608392
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Source/WebCore/fileapi/FileReaderLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,16 @@ void FileReaderLoader::cleanup()
}
}

void FileReaderLoader::didReceiveResponse(ResourceLoaderIdentifier, const ResourceResponse& response)
bool FileReaderLoader::processResponse(const ResourceResponse& response)
{
if (response.httpStatusCode() != httpStatus200OK) {
failed(httpStatusCodeToErrorCode(response.httpStatusCode()));
return;
return false;
}

if (m_readType == ReadType::ReadAsBinaryChunks)
return true;

long long length = response.expectedContentLength();

// A negative value means that the content length wasn't specified, so the buffer will need to be dynamically grown.
Expand All @@ -155,18 +158,25 @@ void FileReaderLoader::didReceiveResponse(ResourceLoaderIdentifier, const Resour
// FIXME: Support reading more than the current size limit of ArrayBuffer.
if (length > std::numeric_limits<unsigned>::max()) {
failed(ExceptionCode::NotReadableError);
return;
return false;
}

ASSERT(!m_rawData);
m_rawData = ArrayBuffer::tryCreate(static_cast<unsigned>(length), 1);

if (!m_rawData) {
failed(ExceptionCode::NotReadableError);
return;
return false;
}

m_totalBytes = static_cast<unsigned>(length);
return true;
}

void FileReaderLoader::didReceiveResponse(ResourceLoaderIdentifier, const ResourceResponse& response)
{
if (!processResponse(response))
return;

if (m_client)
m_client->didStartLoading();
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/fileapi/FileReaderLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class FileReaderLoader final : public ThreadableLoaderClient {
void failed(ExceptionCode);
void convertToText();
void convertToDataURL();
bool processResponse(const ResourceResponse&);

static ExceptionCode httpStatusCodeToErrorCode(int);
static ExceptionCode toErrorCode(BlobResourceHandle::Error);
Expand Down

0 comments on commit 0608392

Please sign in to comment.