Bug 1418425 - Update bsdiff to use libz instead of bz2 for the crc algo r?glandium draft
authorSylvestre Ledru <sledru@mozilla.com>
Fri, 12 Jan 2018 16:13:45 +0100
changeset 786505 7518a96074812a4b6ca74a560376f6af2a5098be
parent 786504 8b9a7774ad6fd4fc17c93bbae2a8ace0e10abf12
child 786506 249358b13cd149e6a0623e7a2c3a49e59ed7c490
push id107494
push userbmo:sledru@mozilla.com
push dateMon, 23 Apr 2018 13:03:04 +0000
reviewersglandium
bugs1418425
milestone61.0a1
Bug 1418425 - Update bsdiff to use libz instead of bz2 for the crc algo r?glandium MozReview-Commit-ID: 2GLmnzF9CMh
other-licenses/bsdiff/bsdiff.c
other-licenses/bsdiff/moz.build
--- a/other-licenses/bsdiff/bsdiff.c
+++ b/other-licenses/bsdiff/bsdiff.c
@@ -9,16 +9,19 @@
 
   ChangeLog:
   2005-05-05 - Use the modified header struct from bspatch.h; use 32-bit
                values throughout.
                  --Benjamin Smedberg <benjamin@smedbergs.us>
   2005-05-18 - Use the same CRC algorithm as bzip2, and leverage the CRC table
                provided by libbz2.
                  --Darin Fisher <darin@meer.net>
+  2017-11-25 - Use zlib instead of bz2 for the CRC function
+                 --Sylvestre Ledru <s@mozilla.com>
+
 */
 
 #include "bspatch.h"
 
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <fcntl.h>
@@ -26,39 +29,20 @@
 #ifdef XP_WIN
 #include <io.h>
 #include <winsock2.h>
 #else
 #include <unistd.h>
 #include <arpa/inet.h>
 #define _O_BINARY 0
 #endif
-
 #undef MIN
 #define MIN(x,y) (((x)<(y)) ? (x) : (y))
 
-/*---------------------------------------------------------------------------*/
-
-/* This variable lives in libbz2.  It's declared in bzlib_private.h, so we just
- * declare it here to avoid including that entire header file.
- */
-extern unsigned int BZ2_crc32Table[256];
-
-static unsigned int
-crc32(const unsigned char *buf, unsigned int len)
-{
-	unsigned int crc = 0xffffffffL;
-
-	const unsigned char *end = buf + len;
-	for (; buf != end; ++buf)
-		crc = (crc << 8) ^ BZ2_crc32Table[(crc >> 24) ^ *buf];
-
-	crc = ~crc;
-	return crc;
-}
+#include "zlib.h"
 
 /*---------------------------------------------------------------------------*/
 
 static void
 reporterr(int e, const char *fmt, ...)
 {
 	if (fmt) {
 		va_list args;
@@ -222,17 +206,17 @@ int main(int argc,char *argv[])
 
 	int32_t s,Sf,lenf,Sb,lenb;
 	int32_t overlap,Ss,lens;
 	int32_t i;
 
 	int32_t dblen,eblen;
 	unsigned char *db,*eb;
 
-	unsigned int scrc;
+	unsigned int scrc = crc32(0L, Z_NULL, 0);
 
 	MBSPatchHeader header = {
 		{'M','B','D','I','F','F','1','0'},
 		0, 0, 0, 0, 0, 0
 	};
 
 	uint32_t numtriples;
 
@@ -244,17 +228,17 @@ int main(int argc,char *argv[])
 	if(((fd=open(argv[1],O_RDONLY|_O_BINARY,0))<0) ||
 		((oldsize=lseek(fd,0,SEEK_END))==-1) ||
 		((old=(unsigned char*) malloc(oldsize+1))==NULL) ||
 		(lseek(fd,0,SEEK_SET)!=0) ||
 		(read(fd,old,oldsize)!=oldsize) ||
 		(close(fd)==-1))
 		reporterr(1,"%s\n",argv[1]);
 
-	scrc = crc32(old, oldsize);
+        scrc = crc32(scrc, old, oldsize);
 
 	if(((I=(int32_t*) malloc((oldsize+1)*sizeof(int32_t)))==NULL) ||
 		((V=(int32_t*) malloc((oldsize+1)*sizeof(int32_t)))==NULL))
 		reporterr(1,NULL);
 
 	qsufsort(I,V,old,oldsize);
 
 	free(V);
--- a/other-licenses/bsdiff/moz.build
+++ b/other-licenses/bsdiff/moz.build
@@ -5,26 +5,26 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 HOST_SOURCES += [
     'bsdiff.c',
 ]
 
 HostProgram('mbsdiff')
 
-if CONFIG['MOZ_SYSTEM_BZ2']:
-    HOST_OS_LIBS += CONFIG['MOZ_BZ2_LIBS']
-else:
-    HOST_USE_LIBS += [
-        'hostbz2',
-    ]
-
 if CONFIG['HOST_OS_ARCH'] == 'WINNT':
     HOST_OS_LIBS += [
         'ws2_32',
+        'vcruntime',
     ]
     USE_STATIC_LIBS = True
 
 LOCAL_INCLUDES += [
     '/toolkit/mozapps/update/updater',
 ]
 
-HOST_CXXFLAGS += CONFIG['MOZ_BZ2_CFLAGS']
+if CONFIG['MOZ_SYSTEM_ZLIB']:
+    HOST_CFLAGS += CONFIG['MOZ_ZLIB_CFLAGS']
+    HOST_OS_LIBS += CONFIG['MOZ_ZLIB_LIBS']
+else:
+    LOCAL_INCLUDES += ['/modules/zlib/src']
+    HOST_USE_LIBS += ['hostzlib']
+