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 266189 62bb5056f458
parent 266188 634d32969bd6
child 266190 d51242ae365d
child 266192 263f9318751a
push id4780
push userryanvm@gmail.com
push date2015-06-04 17:55 +0000
treeherdermozilla-beta@62bb5056f458 [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.