Skip to content

Commit 15daadb

Browse files
committed
Bug 215450: Allow uploading of files greater than 2gb in size. Involves making input streams 64-bit capable. Significant work done by Makoto Kato, finished by Honza Bambas. r=hbambas,bsmedberg,jdrew,sicking
1 parent dde4293 commit 15daadb

File tree

83 files changed

+363
-241
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+363
-241
lines changed

content/base/src/nsFrameMessageManager.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,9 +808,13 @@ nsFrameScriptExecutor::LoadFrameScriptInternal(const nsAString& aURL)
808808
nsCOMPtr<nsIInputStream> input;
809809
channel->Open(getter_AddRefs(input));
810810
nsString dataString;
811-
PRUint32 avail = 0;
812-
if (input && NS_SUCCEEDED(input->Available(&avail)) && avail) {
811+
PRUint64 avail64 = 0;
812+
if (input && NS_SUCCEEDED(input->Available(&avail64)) && avail64) {
813+
if (avail64 > PR_UINT32_MAX) {
814+
return;
815+
}
813816
nsCString buffer;
817+
PRUint32 avail = (PRUint32)NS_MIN(avail64, (PRUint64)PR_UINT32_MAX);
814818
if (NS_FAILED(NS_ReadInputStreamToString(input, buffer, avail))) {
815819
return;
816820
}

content/base/src/nsSyncLoadService.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,9 @@ nsSyncLoadService::PushSyncStreamToListener(nsIInputStream* aIn,
352352
// Load
353353
rv = aListener->OnStartRequest(aChannel, nullptr);
354354
if (NS_SUCCEEDED(rv)) {
355-
PRUint32 sourceOffset = 0;
355+
PRUint64 sourceOffset = 0;
356356
while (1) {
357-
PRUint32 readCount = 0;
357+
PRUint64 readCount = 0;
358358
rv = aIn->Available(&readCount);
359359
if (NS_FAILED(rv) || !readCount) {
360360
if (rv == NS_BASE_STREAM_CLOSED) {
@@ -364,8 +364,12 @@ nsSyncLoadService::PushSyncStreamToListener(nsIInputStream* aIn,
364364
break;
365365
}
366366

367+
if (readCount > PR_UINT32_MAX)
368+
readCount = PR_UINT32_MAX;
369+
367370
rv = aListener->OnDataAvailable(aChannel, nullptr, aIn,
368-
sourceOffset, readCount);
371+
(PRUint32)NS_MIN(sourceOffset, (PRUint64)PR_UINT32_MAX),
372+
(PRUint32)readCount);
369373
if (NS_FAILED(rv)) {
370374
break;
371375
}

content/base/src/nsXMLHttpRequest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2962,7 +2962,7 @@ nsXMLHttpRequest::Send(nsIVariant* aVariant, const Nullable<RequestBody>& aBody)
29622962
}
29632963

29642964
mUploadComplete = false;
2965-
PRUint32 uploadTotal = 0;
2965+
PRUint64 uploadTotal = 0;
29662966
postDataStream->Available(&uploadTotal);
29672967
mUploadTotal = uploadTotal;
29682968

content/html/content/src/nsHTMLCanvasElement.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,12 @@ nsHTMLCanvasElement::ToDataURLImpl(const nsAString& aMimeType,
359359
aDataURL = NS_LITERAL_STRING("data:") + type +
360360
NS_LITERAL_STRING(";base64,");
361361

362-
PRUint32 count;
362+
PRUint64 count;
363363
rv = stream->Available(&count);
364364
NS_ENSURE_SUCCESS(rv, rv);
365+
NS_ENSURE_TRUE(count <= PR_UINT32_MAX, NS_ERROR_FILE_TOO_BIG);
365366

366-
return Base64EncodeInputStream(stream, aDataURL, count, aDataURL.Length());
367+
return Base64EncodeInputStream(stream, aDataURL, (PRUint32)count, aDataURL.Length());
367368
}
368369

369370
NS_IMETHODIMP
@@ -398,17 +399,18 @@ nsHTMLCanvasElement::MozGetAsFileImpl(const nsAString& aName,
398399
type.AssignLiteral("image/png");
399400
}
400401

401-
PRUint32 imgSize;
402+
PRUint64 imgSize;
402403
rv = stream->Available(&imgSize);
403404
NS_ENSURE_SUCCESS(rv, rv);
405+
NS_ENSURE_TRUE(imgSize <= PR_UINT32_MAX, NS_ERROR_FILE_TOO_BIG);
404406

405407
void* imgData = nullptr;
406-
rv = NS_ReadInputStreamToBuffer(stream, &imgData, imgSize);
408+
rv = NS_ReadInputStreamToBuffer(stream, &imgData, (PRUint32)imgSize);
407409
NS_ENSURE_SUCCESS(rv, rv);
408410

409411
// The DOMFile takes ownership of the buffer
410412
nsRefPtr<nsDOMMemoryFile> file =
411-
new nsDOMMemoryFile(imgData, imgSize, aName, type);
413+
new nsDOMMemoryFile(imgData, (PRUint32)imgSize, aName, type);
412414

413415
file.forget(aResult);
414416
return NS_OK;

content/media/MediaResource.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,13 +1053,13 @@ nsresult FileMediaResource::Open(nsIStreamListener** aStreamListener)
10531053
return NS_ERROR_FAILURE;
10541054
}
10551055

1056-
// Get the file size and inform the decoder. Only files up to 4GB are
1057-
// supported here.
1058-
PRUint32 size;
1056+
// Get the file size and inform the decoder.
1057+
PRUint64 size;
10591058
rv = mInput->Available(&size);
1060-
if (NS_SUCCEEDED(rv)) {
1061-
mSize = size;
1062-
}
1059+
NS_ENSURE_SUCCESS(rv, rv);
1060+
NS_ENSURE_TRUE(size <= PR_INT64_MAX, NS_ERROR_FILE_TOO_BIG);
1061+
1062+
mSize = (PRInt64)size;
10631063

10641064
nsCOMPtr<nsIRunnable> event = new LoadedEvent(mDecoder);
10651065
NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);

content/xul/document/src/nsXULPrototypeCache.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,17 @@ nsXULPrototypeCache::BeginCaching(nsIURI* aURI)
646646
rv = tmp;
647647
}
648648
}
649-
if (NS_SUCCEEDED(rv))
650-
rv = inputStream->Available(&len);
649+
650+
if (NS_SUCCEEDED(rv)) {
651+
PRUint64 len64;
652+
rv = inputStream->Available(&len64);
653+
if (NS_SUCCEEDED(rv)) {
654+
if (len64 <= PR_UINT32_MAX)
655+
len = (PRUint32)len64;
656+
else
657+
rv = NS_ERROR_FILE_TOO_BIG;
658+
}
659+
}
651660

652661
if (NS_SUCCEEDED(rv)) {
653662
buf = new char[len];

dom/base/nsJSEnvironment.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3897,11 +3897,13 @@ ReadSourceFromFilename(JSContext *cx, const char *filename, jschar **src, PRUint
38973897
rv = scriptChannel->Open(getter_AddRefs(scriptStream));
38983898
NS_ENSURE_SUCCESS(rv, rv);
38993899

3900-
PRUint32 rawLen;
3900+
PRUint64 rawLen;
39013901
rv = scriptStream->Available(&rawLen);
39023902
NS_ENSURE_SUCCESS(rv, rv);
39033903
if (!rawLen)
39043904
return NS_ERROR_FAILURE;
3905+
if (rawLen > PR_UINT32_MAX)
3906+
return NS_ERROR_FILE_TOO_BIG;
39053907

39063908
// Allocate an internal buf the size of the file.
39073909
nsAutoArrayPtr<unsigned char> buf(new unsigned char[rawLen]);

dom/devicestorage/nsDeviceStorage.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ DeviceStorageFile::Write(nsIInputStream* aInputStream)
158158
return rv;
159159
}
160160

161-
PRUint32 bufSize;
161+
PRUint64 bufSize = 0;
162162
aInputStream->Available(&bufSize);
163163

164164
nsCOMPtr<nsIOutputStream> outputStream;
@@ -177,12 +177,20 @@ DeviceStorageFile::Write(nsIInputStream* aInputStream)
177177
return NS_ERROR_FAILURE;
178178
}
179179

180-
PRUint32 wrote;
181-
bufferedOutputStream->WriteFrom(aInputStream, bufSize, &wrote);
180+
rv = NS_OK;
181+
while (bufSize) {
182+
PRUint32 wrote;
183+
rv = bufferedOutputStream->WriteFrom(aInputStream, static_cast<PRUint32>(NS_MIN<PRUint64>(bufSize, PR_UINT32_MAX)), &wrote);
184+
if (NS_FAILED(rv)) {
185+
break;
186+
}
187+
bufSize -= wrote;
188+
}
189+
182190
bufferedOutputStream->Close();
183191
outputStream->Close();
184-
if (bufSize != wrote) {
185-
return NS_ERROR_FAILURE;
192+
if (NS_FAILED(rv)) {
193+
return rv;
186194
}
187195
return NS_OK;
188196
}

dom/file/ArchiveZipFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ ArchiveInputStream::Close()
169169
}
170170

171171
NS_IMETHODIMP
172-
ArchiveInputStream::Available(PRUint32* _retval)
172+
ArchiveInputStream::Available(PRUint64* _retval)
173173
{
174174
*_retval = mLength - mZs.total_out - mStart;
175175
return NS_OK;

dom/file/FileStreamWrappers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ FileInputStreamWrapper::Close()
139139
}
140140

141141
NS_IMETHODIMP
142-
FileInputStreamWrapper::Available(PRUint32* _retval)
142+
FileInputStreamWrapper::Available(PRUint64* _retval)
143143
{
144144
// Performing sync IO on the main thread is generally not allowed.
145145
// However, the input stream wrapper is also used to track reads performed by

0 commit comments

Comments
 (0)