diff --git a/netwerk/base/nsIncrementalStreamLoader.cpp b/netwerk/base/nsIncrementalStreamLoader.cpp index 4b5792c833bc..b88aa55970b4 100644 --- a/netwerk/base/nsIncrementalStreamLoader.cpp +++ b/netwerk/base/nsIncrementalStreamLoader.cpp @@ -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::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(contentLength) > + std::min(std::numeric_limits::max(), + static_cast(std::numeric_limits::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;