Bug 1167888 - Better string length check in nsZipArchive::BuildFileList. r=smaug, a=dveditz
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 04 Jun 2015 15:04:10 +0100
changeset 267651 62bb5056f458c981aefd96799c0f5d512df197c1
parent 267650 634d32969bd6b907fc85363b2a96baa4747cfe9d
child 267652 d51242ae365d9b0658c432882f5266cb1b41f6a2
child 267654 263f9318751aa79486a7cfd0294c84ce882a62e3
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, dveditz
bugs1167888
milestone39.0
Bug 1167888 - Better string length check in nsZipArchive::BuildFileList. r=smaug, a=dveditz
modules/libjar/nsZipArchive.cpp
--- a/modules/libjar/nsZipArchive.cpp
+++ b/modules/libjar/nsZipArchive.cpp
@@ -639,18 +639,23 @@ MOZ_WIN_MEM_TRY_BEGIN
           break;
         }
       }
   }
 
   if (!centralOffset)
     return NS_ERROR_FILE_CORRUPTED;
 
+  buf = startp + centralOffset;
+
+  // avoid overflow of startp + centralOffset.
+  if (buf < startp)
+    return NS_ERROR_FILE_CORRUPTED;
+
   //-- Read the central directory headers
-  buf = startp + centralOffset;
   uint32_t sig = 0;
   while (buf + int32_t(sizeof(uint32_t)) <= endp &&
          (sig = xtolong(buf)) == CENTRALSIG) {
     // Make sure there is enough data available.
     if (endp - buf < ZIPCENTRAL_SIZE)
       return NS_ERROR_FILE_CORRUPTED;
 
     // Read the fixed-size data.