Backed out changeset 2b4f08a645a0 (bug 1468552) for syntax strictness failure in bspatch.cpp. CLOSED TREE
authorSebastian Hengst <archaeopteryx@coole-files.de>
Tue, 27 Nov 2018 18:58:55 +0200
changeset 504763 e45d7cae915a56013eaa2f6a8f09788fa0b032c7
parent 504762 f8fc57f3ab6450a5f32e282c4f0d02cc8a9eb73e
child 504764 e2d3dd273e41b208f434a19b48dc04e5efa64ad2
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1468552
milestone65.0a1
backs out2b4f08a645a0385021b64b4f995c18cb2250a5c6
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
Backed out changeset 2b4f08a645a0 (bug 1468552) for syntax strictness failure in bspatch.cpp. CLOSED TREE
toolkit/mozapps/update/updater/bspatch.cpp
--- a/toolkit/mozapps/update/updater/bspatch.cpp
+++ b/toolkit/mozapps/update/updater/bspatch.cpp
@@ -66,151 +66,122 @@ MBS_ReadHeader(FILE* file, MBSPatchHeade
   header->scrc32    = ntohl(header->scrc32);
   header->dlen      = ntohl(header->dlen);
   header->cblen     = ntohl(header->cblen);
   header->difflen   = ntohl(header->difflen);
   header->extralen  = ntohl(header->extralen);
 
   struct stat hs;
   s = fstat(fileno(file), &hs);
-  if (s != 0)
+  if (s)
     return READ_ERROR;
 
   if (memcmp(header->tag, "MBDIFF10", 8) != 0)
     return UNEXPECTED_BSPATCH_ERROR;
 
-  if (hs.st_size > INT_MAX)
-    return UNEXPECTED_BSPATCH_ERROR;
-
-  size_t size = static_cast<size_t>(hs.st_size);
-  if (size < sizeof(MBSPatchHeader))
-    return UNEXPECTED_BSPATCH_ERROR;
-  size -= sizeof(MBSPatchHeader);
-
-  if (size < header->cblen)
-    return UNEXPECTED_BSPATCH_ERROR;
-  size -= header->cblen;
-
-  if (size < header->difflen)
-    return UNEXPECTED_BSPATCH_ERROR;
-  size -= header->difflen;
-
-  if (size < header->extralen)
-    return UNEXPECTED_BSPATCH_ERROR;
-  size -= header->extralen;
-
-  if (size != 0)
+  if (sizeof(MBSPatchHeader) +
+      header->cblen +
+      header->difflen +
+      header->extralen != uint32_t(hs.st_size))
     return UNEXPECTED_BSPATCH_ERROR;
 
   return OK;
 }
 
 int
 MBS_ApplyPatch(const MBSPatchHeader *header, FILE* patchFile,
                unsigned char *fbuffer, FILE* file)
 {
-  unsigned char *fbufstart = fbuffer;
   unsigned char *fbufend = fbuffer + header->slen;
 
   unsigned char *buf = (unsigned char*) malloc(header->cblen +
                                                header->difflen +
                                                header->extralen);
   if (!buf)
     return BSPATCH_MEM_ERROR;
 
   int rv = OK;
 
   size_t r = header->cblen + header->difflen + header->extralen;
   unsigned char *wb = buf;
   while (r) {
     const size_t count = (r > SSIZE_MAX) ? SSIZE_MAX : r;
     size_t c = fread(wb, 1, count, patchFile);
-    if (c < 0 && c != count) {
+    if (c != count) {
       rv = READ_ERROR;
       goto end;
     }
 
     r -= c;
     wb += c;
-
-    if (c == 0 && r) {
-      rv = UNEXPECTED_BSPATCH_ERROR;
-      goto end;
-    }
   }
 
   {
     MBSPatchTriple *ctrlsrc = (MBSPatchTriple*) buf;
-    if (header->cblen % sizeof(MBSPatchTriple) != 0) {
-      rv = UNEXPECTED_BSPATCH_ERROR;
-      goto end;
-    }
-
     unsigned char *diffsrc = buf + header->cblen;
     unsigned char *extrasrc = diffsrc + header->difflen;
 
     MBSPatchTriple *ctrlend = (MBSPatchTriple*) diffsrc;
     unsigned char *diffend = extrasrc;
     unsigned char *extraend = extrasrc + header->extralen;
 
-    while (ctrlsrc < ctrlend) {
+    do {
       ctrlsrc->x = ntohl(ctrlsrc->x);
       ctrlsrc->y = ntohl(ctrlsrc->y);
       ctrlsrc->z = ntohl(ctrlsrc->z);
 
 #ifdef DEBUG_bsmedberg
       printf("Applying block:\n"
              " x: %u\n"
              " y: %u\n"
              " z: %i\n",
              ctrlsrc->x,
              ctrlsrc->y,
              ctrlsrc->z);
 #endif
 
       /* Add x bytes from oldfile to x bytes from the diff block */
 
-      if (ctrlsrc->x > static_cast<size_t>(fbufend - fbuffer) ||
-          ctrlsrc->x > static_cast<size_t>(diffend - diffsrc)) {
+      if (fbuffer + ctrlsrc->x > fbufend ||
+          diffsrc + ctrlsrc->x > diffend) {
         rv = UNEXPECTED_BSPATCH_ERROR;
         goto end;
       }
       for (uint32_t i = 0; i < ctrlsrc->x; ++i) {
         diffsrc[i] += fbuffer[i];
       }
       if ((uint32_t) fwrite(diffsrc, 1, ctrlsrc->x, file) != ctrlsrc->x) {
         rv = WRITE_ERROR_PATCH_FILE;
         goto end;
       }
       fbuffer += ctrlsrc->x;
       diffsrc += ctrlsrc->x;
 
       /* Copy y bytes from the extra block */
 
-      if (ctrlsrc->y > static_cast<size_t>(extraend - extrasrc)) {
+      if (extrasrc + ctrlsrc->y > extraend) {
         rv = UNEXPECTED_BSPATCH_ERROR;
         goto end;
       }
       if ((uint32_t) fwrite(extrasrc, 1, ctrlsrc->y, file) != ctrlsrc->y) {
         rv = WRITE_ERROR_PATCH_FILE;
         goto end;
       }
       extrasrc += ctrlsrc->y;
 
       /* "seek" forwards in oldfile by z bytes */
 
-      if (ctrlsrc->z < fbufstart - fbuffer ||
-          ctrlsrc->z > fbufend - fbuffer) {
+      if (fbuffer + ctrlsrc->z > fbufend) {
         rv = UNEXPECTED_BSPATCH_ERROR;
         goto end;
       }
       fbuffer += ctrlsrc->z;
 
       /* and on to the next control block */
 
       ++ctrlsrc;
-    }
+    } while (ctrlsrc < ctrlend);
   }
 
 end:
   free(buf);
   return rv;
 }