Bug 1674777 part 7 - Change nsIBinaryInputStream.readArrayBuffer to use uint64_t instead of uint32_t. r=kmag

We're adding support for ArrayBuffers larger than 4 GB to the JS engine (on 64-bit
platforms).

ReadArrayBuffer uses uint32_t values in a number of places. This patch changes them
to uint64_t where necessary. Values related to the temporary buffer stay uint32_t because
that buffer is <= 4096 bytes.

Differential Revision: https://phabricator.services.mozilla.com/D103759
This commit is contained in:
Jan de Mooij 2021-02-10 08:30:05 +00:00
Родитель 9ea20acd3b
Коммит c4b59c1ae8
2 изменённых файлов: 7 добавлений и 7 удалений

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

@ -786,9 +786,9 @@ nsBinaryInputStream::ReadByteArray(uint32_t aLength,
}
NS_IMETHODIMP
nsBinaryInputStream::ReadArrayBuffer(uint32_t aLength,
nsBinaryInputStream::ReadArrayBuffer(uint64_t aLength,
JS::Handle<JS::Value> aBuffer,
JSContext* aCx, uint32_t* aReadLength) {
JSContext* aCx, uint64_t* aReadLength) {
if (!aBuffer.isObject()) {
return NS_ERROR_FAILURE;
}
@ -797,20 +797,20 @@ nsBinaryInputStream::ReadArrayBuffer(uint32_t aLength,
return NS_ERROR_FAILURE;
}
uint32_t bufferLength = JS::GetArrayBufferByteLength(buffer);
size_t bufferLength = JS::GetArrayBufferByteLength(buffer);
if (bufferLength < aLength) {
return NS_ERROR_FAILURE;
}
uint32_t bufSize = std::min<uint32_t>(aLength, 4096);
uint32_t bufSize = std::min<uint64_t>(aLength, 4096);
UniquePtr<char[]> buf = MakeUnique<char[]>(bufSize);
uint32_t pos = 0;
uint64_t pos = 0;
*aReadLength = 0;
do {
// Read data into temporary buffer.
uint32_t bytesRead;
uint32_t amount = std::min(aLength - pos, bufSize);
uint32_t amount = std::min<uint64_t>(aLength - pos, bufSize);
nsresult rv = Read(buf.get(), amount, &bytesRead);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;

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

@ -78,7 +78,7 @@ interface nsIBinaryInputStream : nsIInputStream {
* @return The number of bytes actually read into aArrayBuffer.
*/
[implicit_jscontext]
unsigned long readArrayBuffer(in uint32_t aLength, in jsval aArrayBuffer);
uint64_t readArrayBuffer(in uint64_t aLength, in jsval aArrayBuffer);
};
%{C++