Bug 1410379 - compare uint64_t with size_t only on 32bit platforms. r=valentin

MozReview-Commit-ID: 1exUwUwaY3B

--HG--
extra : rebase_source : 83f199c92e641baa5c44fd65095a87af0528863e
This commit is contained in:
Andi-Bogdan Postelnicu 2017-10-20 15:46:28 +03:00
parent 9bf7d76660
commit c9decadfc3

View File

@ -69,10 +69,15 @@ nsIncrementalStreamLoader::OnStartRequest(nsIRequest* request, nsISupports *ctxt
int64_t contentLength = -1;
chan->GetContentLength(&contentLength);
if (contentLength >= 0) {
if (uint64_t(contentLength) > std::numeric_limits<size_t>::max()) {
// On 64bit platforms size of uint64_t coincides with the size of size_t,
// so we want to compare with the minimum from size_t and int64_t. */
if (static_cast<uint64_t>(contentLength) >
std::min(std::numeric_limits<size_t>::max(),
static_cast<size_t>(std::numeric_limits<int64_t>::max()))) {
// Too big to fit into size_t, so let's bail.
return NS_ERROR_OUT_OF_MEMORY;
}
// preallocate buffer
if (!mData.initCapacity(contentLength)) {
return NS_ERROR_OUT_OF_MEMORY;