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 201217 917d8e07d42b23177e5cdf6a79dbd5a16513e34e
parent 201216 b64bd97203674ffb21afb3ca5e89c1976eab40d9
child 201218 748f7fec6ebbacfd198b2cc8251fe15e6d961096
push id280
push userryanvm@gmail.com
push dateThu, 04 Jun 2015 20:27:19 +0000
treeherdermozilla-esr31@917d8e07d42b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, dveditz
bugs1167888
milestone31.7.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
@@ -612,18 +612,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.