Bug 1587534 - nsHttpChannel can return invalid content length for alternative data, r=valentin
authorMichal Novotny <michal.novotny@gmail.com>
Thu, 28 Nov 2019 11:09:09 +0000
changeset 504254 c67998c390c1323d91cc4441b5f3a9faa48b8f84
parent 504253 10b86ccc0de62910449e858ab8e3e13653795135
child 504255 3238ac73b187072a264162769742ebd055bada45
push id36859
push userrgurzau@mozilla.com
push dateThu, 28 Nov 2019 21:48:53 +0000
treeherdermozilla-central@5afa8f03bfed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin
bugs1587534
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1587534 - nsHttpChannel can return invalid content length for alternative data, r=valentin CacheEntry::GetAltDataSize() can throw an error if the size isn't known yet, i.e. when the output stream wasn't closed yet. nsHttpChannel::OpenCacheInputStream() doesn't check the return value and in case of failure uninitialized altDataSize is stored in mAltDataLength. Differential Revision: https://phabricator.services.mozilla.com/D55085
netwerk/protocol/http/nsHttpChannel.cpp
--- a/netwerk/protocol/http/nsHttpChannel.cpp
+++ b/netwerk/protocol/http/nsHttpChannel.cpp
@@ -5061,30 +5061,33 @@ nsresult nsHttpChannel::OpenCacheInputSt
         foundAltData = true;
         deliverAltData = pref.deliverAltData();
         break;
       }
     }
   }
 
   nsCOMPtr<nsIInputStream> altData;
-  int64_t altDataSize;
+  int64_t altDataSize = -1;
   if (foundAltData) {
     rv = cacheEntry->OpenAlternativeInputStream(altDataType,
                                                 getter_AddRefs(altData));
     if (NS_SUCCEEDED(rv)) {
-      LOG(("Opened alt-data input stream type=%s", altDataType.get()));
       // We have succeeded.
       mAvailableCachedAltDataType = altDataType;
       mDeliveringAltData = deliverAltData;
 
       // Set the correct data size on the channel.
       Unused << cacheEntry->GetAltDataSize(&altDataSize);
       mAltDataLength = altDataSize;
 
+      LOG(("Opened alt-data input stream [type=%s, size=%" PRId64
+           ", deliverAltData=%d]",
+           altDataType.get(), mAltDataLength, deliverAltData));
+
       if (deliverAltData) {
         stream = altData;
       }
     }
   }
 
   if (!stream) {
     rv = cacheEntry->OpenInputStream(0, getter_AddRefs(stream));