Bug 1410379 - compare uint64_t with size_t only on 32bit platforms. r?valentin draft
authorAndi-Bogdan Postelnicu <bpostelnicu@mozilla.com>
Fri, 20 Oct 2017 15:46:28 +0300
changeset 683893 b2f05b2625b93c7a5c047474ddd32429e42f7692
parent 683863 d1e995c8640a191cd127e87273ec96cb2fabffa9
child 736750 a6f8b1f49b40e314705714a05da182261b902aa0
push id85489
push userbmo:bpostelnicu@mozilla.com
push dateFri, 20 Oct 2017 12:47:19 +0000
reviewersvalentin
bugs1410379
milestone58.0a1
Bug 1410379 - compare uint64_t with size_t only on 32bit platforms. r?valentin MozReview-Commit-ID: 1exUwUwaY3B
netwerk/base/nsIncrementalStreamLoader.cpp
--- a/netwerk/base/nsIncrementalStreamLoader.cpp
+++ b/netwerk/base/nsIncrementalStreamLoader.cpp
@@ -64,20 +64,25 @@ nsIncrementalStreamLoader::GetRequest(ns
 NS_IMETHODIMP
 nsIncrementalStreamLoader::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
 {
   nsCOMPtr<nsIChannel> chan( do_QueryInterface(request) );
   if (chan) {
     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;
       }
     }
   }
   mContext = ctxt;
   return NS_OK;