summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh MacDonald <josh.macdonald@gmail.com>2015-10-31 22:34:32 -0700
committerJosh MacDonald <josh.macdonald@gmail.com>2015-10-31 22:34:32 -0700
commit65e39a369ce7befe18cfcb350e4d3cc391cc09f2 (patch)
treec28e4d9dc8c94f9d61a2cfcc5600e691a3eebdbd
parent33bc5056a256f3a49da2062b2e383cbeed2d2b8b (diff)
parent482c20590f29c91a06430d2818a140257826ac01 (diff)
Merge ~6 AFL decoder fixes from head; AFL support in run_release.sh
-rw-r--r--.gitignore2
-rw-r--r--xdelta3/Makefile.am5
-rw-r--r--xdelta3/configure.ac2
-rwxr-xr-xxdelta3/run_release.sh73
-rw-r--r--xdelta3/testing/checksum_test.cc2
-rw-r--r--xdelta3/testing/file.h2
-rw-r--r--xdelta3/xdelta3-decode.h51
-rw-r--r--xdelta3/xdelta3-internal.h6
-rw-r--r--xdelta3/xdelta3-main.h123
-rw-r--r--xdelta3/xdelta3-second.h6
-rw-r--r--xdelta3/xdelta3-test.h56
-rw-r--r--xdelta3/xdelta3.c5
-rw-r--r--xdelta3/xdelta3.prj61
13 files changed, 225 insertions, 169 deletions
diff --git a/.gitignore b/.gitignore
index 58a9163..a5b5926 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,6 +27,6 @@ ltversion.m4
27lt~obsolete.m4 27lt~obsolete.m4
28missing 28missing
29stamp-h1 29stamp-h1
30xdelta3 30xdelta3/xdelta3
31xdelta3decode 31xdelta3decode
32xdelta3regtest 32xdelta3regtest
diff --git a/xdelta3/Makefile.am b/xdelta3/Makefile.am
index 322d88d..11f75b0 100644
--- a/xdelta3/Makefile.am
+++ b/xdelta3/Makefile.am
@@ -4,6 +4,8 @@ AUTOMAKE_OPTIONS = subdir-objects
4bin_PROGRAMS = xdelta3 4bin_PROGRAMS = xdelta3
5noinst_PROGRAMS = xdelta3regtest xdelta3decode xdelta3checksum 5noinst_PROGRAMS = xdelta3regtest xdelta3decode xdelta3checksum
6 6
7export AFL_HARDEN
8
7common_SOURCES = \ 9common_SOURCES = \
8 xdelta3-blkcache.h \ 10 xdelta3-blkcache.h \
9 xdelta3-decode.h \ 11 xdelta3-decode.h \
@@ -48,6 +50,7 @@ WFLAGS = -Wall -Wshadow -fno-builtin -Wextra -Wsign-compare \
48C_WFLAGS = $(WFLAGS) -pedantic -std=c99 50C_WFLAGS = $(WFLAGS) -pedantic -std=c99
49CXX_WFLAGS = $(WFLAGS) 51CXX_WFLAGS = $(WFLAGS)
50 52
53# TODO add -O3
51common_CFLAGS = \ 54common_CFLAGS = \
52 -DREGRESSION_TEST=1 \ 55 -DREGRESSION_TEST=1 \
53 -DSECONDARY_DJW=1 \ 56 -DSECONDARY_DJW=1 \
@@ -59,7 +62,7 @@ if DEBUG_SYMBOLS
59endif 62endif
60 63
61# For additional debugging, add -DXD3_DEBUG=1, 2, 3, ... 64# For additional debugging, add -DXD3_DEBUG=1, 2, 3, ...
62xdelta3_CFLAGS = $(C_WFLAGS) $(common_CFLAGS) -DXD3_DEBUG=1 65xdelta3_CFLAGS = $(C_WFLAGS) $(common_CFLAGS) -DXD3_DEBUG=0
63xdelta3_LDADD = -lm 66xdelta3_LDADD = -lm
64 67
65xdelta3decode_CFLAGS = \ 68xdelta3decode_CFLAGS = \
diff --git a/xdelta3/configure.ac b/xdelta3/configure.ac
index af96bc2..dbcac4f 100644
--- a/xdelta3/configure.ac
+++ b/xdelta3/configure.ac
@@ -1,4 +1,4 @@
1AC_INIT([Xdelta3], [3.0.10], [josh.macdonald@gmail.com], 1AC_INIT([Xdelta3], [3.0.11], [josh.macdonald@gmail.com],
2 [xdelta3], [http://xdelta.org/]) 2 [xdelta3], [http://xdelta.org/])
3AC_PREREQ([2.68]) 3AC_PREREQ([2.68])
4AC_CONFIG_MACRO_DIR([m4]) 4AC_CONFIG_MACRO_DIR([m4])
diff --git a/xdelta3/run_release.sh b/xdelta3/run_release.sh
index 1b9dc8c..f38c44d 100755
--- a/xdelta3/run_release.sh
+++ b/xdelta3/run_release.sh
@@ -12,8 +12,8 @@ MAKEFLAGS="-j 10"
12BUILDDIR=${SRCDIR}/build 12BUILDDIR=${SRCDIR}/build
13LZMASRC=${BUILDDIR}/${LZMA} 13LZMASRC=${BUILDDIR}/${LZMA}
14 14
15MINGW_CFLAGS="-DEXTERNAL_COMPRESSION=0 -DVCDIFF_TOOLS=0" 15NONWIN_CFLAGS=""
16MINGW_CFLAGS="${MINGW_CFLAGS} -DXD3_WIN32=1 -DSHELL_TESTS=0" 16MINGW_CFLAGS="-DEXTERNAL_COMPRESSION=0 -DXD3_WIN32=1 -DSHELL_TESTS=0"
17 17
18MYOS=`uname` 18MYOS=`uname`
19DATE=`date` 19DATE=`date`
@@ -40,15 +40,15 @@ if [ "${TMPDIR}" != "" ]; then
40 XTMP="${TMPDIR}" 40 XTMP="${TMPDIR}"
41fi 41fi
42 42
43find build -type f 2> /dev/null | xargs rm 43find build -type f 2> /dev/null | xargs rm -f
44 44
45function setup { 45function setup {
46 mkdir -p ${BUILDDIR} 46 libtoolize
47 automake --add-missing
47 aclocal -I m4 48 aclocal -I m4
48 autoheader 49 autoheader
49 libtoolize
50 automake 50 automake
51 automake --add-missing 51 autoheader
52 autoconf 52 autoconf
53} 53}
54 54
@@ -57,7 +57,7 @@ function try {
57 shift 57 shift
58 local dir=$1 58 local dir=$1
59 shift 59 shift
60 echo -n " ${w} ..." 60 echo -n " ${w} ... "
61 (cd "${dir}" && "$@" >${w}.stdout 2>${w}.stderr) 61 (cd "${dir}" && "$@" >${w}.stdout 2>${w}.stderr)
62 local s=$? 62 local s=$?
63 if [ ${s} -eq 0 ]; then 63 if [ ${s} -eq 0 ]; then
@@ -91,11 +91,11 @@ function buildlzma {
91 91
92 try build-lzma ${target} make ${MAKEFLAGS} 92 try build-lzma ${target} make ${MAKEFLAGS}
93 if [ $? -ne 0 ]; then 93 if [ $? -ne 0 ]; then
94 return 94 return
95 fi 95 fi
96 try install-lzma ${target} make install 96 try install-lzma ${target} make install
97 if [ $? -ne 0 ]; then 97 if [ $? -ne 0 ]; then
98 return 98 return
99 fi 99 fi
100} 100}
101 101
@@ -105,14 +105,26 @@ function buildit {
105 local usizebits=$3 105 local usizebits=$3
106 local offsetbits=$4 106 local offsetbits=$4
107 local cargs=$5 107 local cargs=$5
108 local largs=$6 108 local afl=$6
109 local BM="${host}${march}" 109 local BM="${host}${march}"
110 local USECC="${CC}"
111 local USECXX="${CXX}"
112 local LIBBM="${BM}"
113
114 if [ "${afl}" = "1" ]; then
115 USECC="afl-gcc"
116 USECXX="afl-g++"
117 BM="${BM}-afl"
118 fi
119
110 local D="build/${BM}/usize${usizebits}/xoff${offsetbits}" 120 local D="build/${BM}/usize${usizebits}/xoff${offsetbits}"
111 local BMD="${BM}-${usizebits}-${offsetbits}" 121 local BMD="${BM}-${usizebits}-${offsetbits}"
122
112 local FULLD="${SRCDIR}/${D}" 123 local FULLD="${SRCDIR}/${D}"
113 local CFLAGS="${march} ${cargs} -g -I${SRCDIR}/build/lib-${BM}/include" 124 local CFLAGS="${march} ${cargs} -I${SRCDIR}/build/lib-${LIBBM}/include"
114 local CXXFLAGS="${march} ${cargs} -g -I${SRCDIR}/build/lib-${BM}/include" 125 local CXXFLAGS="${march} ${cargs} -I${SRCDIR}/build/lib-${LIBBM}/include"
115 local LDFLAGS="${largs} ${march} -L${SRCDIR}/build/lib-${BM}/lib" 126 local LDFLAGS="${march} -L${SRCDIR}/build/lib-${LIBBM}/lib"
127
116 mkdir -p ${D} 128 mkdir -p ${D}
117 129
118 echo " ... ${BMD}" 130 echo " ... ${BMD}"
@@ -123,7 +135,7 @@ function buildit {
123# ${CFLAGS} 135# ${CFLAGS}
124.PHONY: build-${BMD} 136.PHONY: build-${BMD}
125build-${BMD}: 137build-${BMD}:
126 (cd ${D} && make all) 138 (cd ${D} && make all && make install)
127 139
128.PHONY: clean-${BMD} 140.PHONY: clean-${BMD}
129clean-${BMD}: 141clean-${BMD}:
@@ -167,22 +179,24 @@ EOF
167 --enable-debug-symbols \ 179 --enable-debug-symbols \
168 "CFLAGS=${CFLAGS}" \ 180 "CFLAGS=${CFLAGS}" \
169 "CXXFLAGS=${CXXFLAGS}" \ 181 "CXXFLAGS=${CXXFLAGS}" \
170 "LDFLAGS=${LDFLAGS}" 182 "LDFLAGS=${LDFLAGS}" \
183 "CC=${USECC}" \
184 "CXX=${USECXX}"
171 if [ $? -ne 0 ]; then 185 if [ $? -ne 0 ]; then
172 return 186 return
173 fi 187 fi
174 188
175 try build-xdelta ${FULLD} make ${MAKEFLAGS} all 189 # try build-xdelta ${FULLD} make ${MAKEFLAGS} all
176 if [ $? -ne 0 ]; then 190 # if [ $? -ne 0 ]; then
177 return 191 # return
178 fi 192 # fi
179 193
180 try install-xdelta ${FULLD} make install 194 # try install-xdelta ${FULLD} make install
181} 195}
182 196
183function buildall { 197function buildall {
184 echo "" 198 echo ""
185 echo "Host $1$2" 199 echo "Host $1$2 afl=$4"
186 echo "" 200 echo ""
187 201
188 buildlzma "$1" "$2" 202 buildlzma "$1" "$2"
@@ -202,28 +216,31 @@ cat > Makefile.test <<EOF
202# Auto-generated ${DATE} -*- Mode: Makefile -*- 216# Auto-generated ${DATE} -*- Mode: Makefile -*-
203TMP = ${XTMP} 217TMP = ${XTMP}
204 218
219all: linux windows apple
220
205EOF 221EOF
206 222
207# Native compiles 223# Native compiles
208if [ "${MYOS}" == "Linux" ]; then 224if [ "${MYOS}" == "Linux" ]; then
209 # Linux 225 # Linux
210 buildall x86_64-pc-linux-gnu -m32 226 buildall x86_64-pc-linux-gnu -m32 "${NONWIN_CFLAGS}" "0"
211 buildall x86_64-pc-linux-gnu -m64 227 buildall x86_64-pc-linux-gnu -m32 "${NONWIN_CFLAGS}" "1"
228 buildall x86_64-pc-linux-gnu -m64 "${NONWIN_CFLAGS}" "0"
229 buildall x86_64-pc-linux-gnu -m64 "${NONWIN_CFLAGS}" "1"
212fi 230fi
213 231
214if [ "${MYOS}" == "Darwin" ]; then 232if [ "${MYOS}" == "Darwin" ]; then
215 # OS X 233 # OS X
216 buildall x86_64-apple-darwin -m32 234 buildall x86_64-apple-darwin -m32 "${NONWIN_CFLAGS}" "0"
217 buildall x86_64-apple-darwin -m64 235 buildall x86_64-apple-darwin -m64 "${NONWIN_CFLAGS}" "0"
218fi 236fi
219 237
220# Cross compile 238# Cross compile
221buildall i686-w64-mingw32 -mconsole "${MINGW_CFLAGS}" 239buildall i686-w64-mingw32 -mconsole "${MINGW_CFLAGS}" "0"
222buildall x86_64-w64-mingw32 -mconsole "${MINGW_CFLAGS}" 240buildall x86_64-w64-mingw32 -mconsole "${MINGW_CFLAGS}" "0"
223 241
224cat >> Makefile.test <<EOF 242cat >> Makefile.test <<EOF
225 243
226all: linux windows apple
227clean: ${CLEAN} 244clean: ${CLEAN}
228 245
229.PHONY: linux windows apple 246.PHONY: linux windows apple
diff --git a/xdelta3/testing/checksum_test.cc b/xdelta3/testing/checksum_test.cc
index 5b57a49..c508753 100644
--- a/xdelta3/testing/checksum_test.cc
+++ b/xdelta3/testing/checksum_test.cc
@@ -473,7 +473,7 @@ struct test_result : public test_result_base {
473 usize_t i; 473 usize_t i;
474 474
475 for (i = 3; i <= bits; i += 1) { 475 for (i = 3; i <= bits; i += 1) {
476 if (slots <= (1 << i)) { 476 if (slots <= (1U << i)) {
477 return i - Checksum::compaction; 477 return i - Checksum::compaction;
478 } 478 }
479 } 479 }
diff --git a/xdelta3/testing/file.h b/xdelta3/testing/file.h
index 05f9dde..c6f3c7b 100644
--- a/xdelta3/testing/file.h
+++ b/xdelta3/testing/file.h
@@ -50,7 +50,7 @@ public:
50 } 50 }
51 data_ = new uint8_t[data_size_]; 51 data_ = new uint8_t[data_size_];
52 memcpy(data_, tmp, size_); 52 memcpy(data_, tmp, size_);
53 delete tmp; 53 delete [] tmp;
54 } 54 }
55 55
56 memcpy(data_ + size_, data, size); 56 memcpy(data_ + size_, data, size);
diff --git a/xdelta3/xdelta3-decode.h b/xdelta3/xdelta3-decode.h
index 7999bc3..abe8c83 100644
--- a/xdelta3/xdelta3-decode.h
+++ b/xdelta3/xdelta3-decode.h
@@ -97,6 +97,15 @@ xd3_decode_setup_buffers (xd3_stream *stream)
97 /* If VCD_TARGET is set then the previous buffer may be reused. */ 97 /* If VCD_TARGET is set then the previous buffer may be reused. */
98 if (stream->dec_win_ind & VCD_TARGET) 98 if (stream->dec_win_ind & VCD_TARGET)
99 { 99 {
100 /* Note: this implementation is untested, since Xdelta3 itself
101 * does not implement an encoder for VCD_TARGET mode. Thus, mark
102 * unimplemented until needed. */
103 if (1)
104 {
105 stream->msg = "VCD_TARGET not implemented";
106 return XD3_UNIMPLEMENTED;
107 }
108
100 /* But this implementation only supports copying from the last 109 /* But this implementation only supports copying from the last
101 * target window. If the offset is outside that range, it can't 110 * target window. If the offset is outside that range, it can't
102 * be done. */ 111 * be done. */
@@ -116,7 +125,7 @@ xd3_decode_setup_buffers (xd3_stream *stream)
116 stream->space_out = 0; 125 stream->space_out = 0;
117 } 126 }
118 127
119 // TODO: VCD_TARGET mode, this is broken 128 /* TODO: (See note above, this looks incorrect) */
120 stream->dec_cpyaddrbase = stream->dec_lastwin + 129 stream->dec_cpyaddrbase = stream->dec_lastwin +
121 (usize_t) (stream->dec_cpyoff - stream->dec_laststart); 130 (usize_t) (stream->dec_cpyoff - stream->dec_laststart);
122 } 131 }
@@ -389,6 +398,13 @@ xd3_decode_output_halfinst (xd3_stream *stream, xd3_hinst *inst)
389 * supplies the data */ 398 * supplies the data */
390 usize_t take = inst->size; 399 usize_t take = inst->size;
391 400
401 if (USIZE_T_OVERFLOW (stream->avail_out, take) ||
402 stream->avail_out + take > stream->space_out)
403 {
404 stream->msg = "overflow while decoding";
405 return XD3_INVALID_INPUT;
406 }
407
392 XD3_ASSERT (inst->type != XD3_NOOP); 408 XD3_ASSERT (inst->type != XD3_NOOP);
393 409
394 switch (inst->type) 410 switch (inst->type)
@@ -460,7 +476,8 @@ xd3_decode_output_halfinst (xd3_stream *stream, xd3_hinst *inst)
460 { 476 {
461 /* TODO: Users have requested long-distance copies of 477 /* TODO: Users have requested long-distance copies of
462 * similar material within a target (e.g., for dup 478 * similar material within a target (e.g., for dup
463 * supression in backups). */ 479 * supression in backups). This code path is probably
480 * dead due to XD3_UNIMPLEMENTED in xd3_decode_setup_buffers */
464 inst->size = 0; 481 inst->size = 0;
465 inst->type = XD3_NOOP; 482 inst->type = XD3_NOOP;
466 stream->msg = "VCD_TARGET not implemented"; 483 stream->msg = "VCD_TARGET not implemented";
@@ -616,10 +633,23 @@ xd3_decode_sections (xd3_stream *stream)
616 return xd3_decode_finish_window (stream); 633 return xd3_decode_finish_window (stream);
617 } 634 }
618 635
619 /* To avoid copying, need this much data available */ 636 /* To avoid extra copying, allocate three sections at once (but
620 need = (stream->inst_sect.size + 637 * check for overflow). */
621 stream->addr_sect.size + 638 need = stream->inst_sect.size;
622 stream->data_sect.size); 639
640 if (USIZE_T_OVERFLOW (need, stream->addr_sect.size))
641 {
642 stream->msg = "decoder section size overflow";
643 return XD3_INTERNAL;
644 }
645 need += stream->addr_sect.size;
646
647 if (USIZE_T_OVERFLOW (need, stream->data_sect.size))
648 {
649 stream->msg = "decoder section size overflow";
650 return XD3_INTERNAL;
651 }
652 need += stream->data_sect.size;
623 653
624 /* The window may be entirely processed. */ 654 /* The window may be entirely processed. */
625 XD3_ASSERT (stream->dec_winbytes <= need); 655 XD3_ASSERT (stream->dec_winbytes <= need);
@@ -887,6 +917,7 @@ xd3_decode_input (xd3_stream *stream)
887 917
888 if ((stream->dec_hdr_ind & VCD_CODETABLE) != 0) 918 if ((stream->dec_hdr_ind & VCD_CODETABLE) != 0)
889 { 919 {
920 stream->msg = "VCD_CODETABLE support was removed";
890 return XD3_UNIMPLEMENTED; 921 return XD3_UNIMPLEMENTED;
891 } 922 }
892 else 923 else
@@ -911,7 +942,13 @@ xd3_decode_input (xd3_stream *stream)
911 if (stream->dec_hdr_ind & VCD_APPHEADER) 942 if (stream->dec_hdr_ind & VCD_APPHEADER)
912 { 943 {
913 /* Note: we add an additional byte for padding, to allow 944 /* Note: we add an additional byte for padding, to allow
914 0-termination. */ 945 0-termination. Check for overflow: */
946 if (USIZE_T_OVERFLOW(stream->dec_appheadsz, 1))
947 {
948 stream->msg = "exceptional appheader size";
949 return XD3_INVALID_INPUT;
950 }
951
915 if ((stream->dec_appheader == NULL) && 952 if ((stream->dec_appheader == NULL) &&
916 (stream->dec_appheader = 953 (stream->dec_appheader =
917 (uint8_t*) xd3_alloc (stream, 954 (uint8_t*) xd3_alloc (stream,
diff --git a/xdelta3/xdelta3-internal.h b/xdelta3/xdelta3-internal.h
index e3568e8..6482721 100644
--- a/xdelta3/xdelta3-internal.h
+++ b/xdelta3/xdelta3-internal.h
@@ -230,7 +230,7 @@ void xprintf(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2);
230 \ 230 \
231 do \ 231 do \
232 { \ 232 { \
233 if (inp == max) \ 233 if (inp == maxp) \
234 { \ 234 { \
235 stream->msg = "end-of-input in read_integer"; \ 235 stream->msg = "end-of-input in read_integer"; \
236 return XD3_INVALID_INPUT; \ 236 return XD3_INVALID_INPUT; \
@@ -290,7 +290,7 @@ xd3_decode_uint32_t (xd3_stream *stream, uint32_t *val)
290 290
291static inline int 291static inline int
292xd3_read_uint32_t (xd3_stream *stream, const uint8_t **inpp, 292xd3_read_uint32_t (xd3_stream *stream, const uint8_t **inpp,
293 const uint8_t *max, uint32_t *valp) 293 const uint8_t *maxp, uint32_t *valp)
294{ READ_INTEGER_TYPE (uint32_t, UINT32_OFLOW_MASK); } 294{ READ_INTEGER_TYPE (uint32_t, UINT32_OFLOW_MASK); }
295 295
296#if XD3_ENCODER 296#if XD3_ENCODER
@@ -323,7 +323,7 @@ xd3_decode_uint64_t (xd3_stream *stream, uint64_t *val)
323 323
324static int 324static int
325xd3_read_uint64_t (xd3_stream *stream, const uint8_t **inpp, 325xd3_read_uint64_t (xd3_stream *stream, const uint8_t **inpp,
326 const uint8_t *max, uint64_t *valp) 326 const uint8_t *maxp, uint64_t *valp)
327{ READ_INTEGER_TYPE (uint64_t, UINT64_OFLOW_MASK); } 327{ READ_INTEGER_TYPE (uint64_t, UINT64_OFLOW_MASK); }
328 328
329#if XD3_ENCODER 329#if XD3_ENCODER
diff --git a/xdelta3/xdelta3-main.h b/xdelta3/xdelta3-main.h
index c3cc4aa..cfc952c 100644
--- a/xdelta3/xdelta3-main.h
+++ b/xdelta3/xdelta3-main.h
@@ -234,7 +234,7 @@ static int option_verbose = DEFAULT_VERBOSE;
234static int option_quiet = 0; 234static int option_quiet = 0;
235static int option_use_appheader = 1; 235static int option_use_appheader = 1;
236static uint8_t* option_appheader = NULL; 236static uint8_t* option_appheader = NULL;
237static int option_use_secondary = 0; 237static int option_use_secondary = 1;
238static const char* option_secondary = NULL; 238static const char* option_secondary = NULL;
239static int option_use_checksum = 1; 239static int option_use_checksum = 1;
240static const char* option_smatch_config = NULL; 240static const char* option_smatch_config = NULL;
@@ -348,7 +348,7 @@ static int
348main_version (void) 348main_version (void)
349{ 349{
350 /* $Format: " XPR(NTR \"Xdelta version $Xdelta3Version$, Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, Joshua MacDonald\\n\");" $ */ 350 /* $Format: " XPR(NTR \"Xdelta version $Xdelta3Version$, Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, Joshua MacDonald\\n\");" $ */
351 XPR(NTR "Xdelta version 3.0.10, Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Joshua MacDonald\n"); 351 XPR(NTR "Xdelta version 3.0.11, Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Joshua MacDonald\n");
352 XPR(NTR "Xdelta comes with ABSOLUTELY NO WARRANTY.\n"); 352 XPR(NTR "Xdelta comes with ABSOLUTELY NO WARRANTY.\n");
353 XPR(NTR "This is free software, and you are welcome to redistribute it\n"); 353 XPR(NTR "This is free software, and you are welcome to redistribute it\n");
354 XPR(NTR "under certain conditions; see \"COPYING\" for details.\n"); 354 XPR(NTR "under certain conditions; see \"COPYING\" for details.\n");
@@ -402,7 +402,7 @@ reset_defaults(void)
402 option_verbose = DEFAULT_VERBOSE; 402 option_verbose = DEFAULT_VERBOSE;
403 option_quiet = 0; 403 option_quiet = 0;
404 option_appheader = NULL; 404 option_appheader = NULL;
405 option_use_secondary = 0; 405 option_use_secondary = 1;
406 option_secondary = NULL; 406 option_secondary = NULL;
407 option_smatch_config = NULL; 407 option_smatch_config = NULL;
408 option_no_compress = 0; 408 option_no_compress = 0;
@@ -1169,70 +1169,72 @@ static int
1169main_set_secondary_flags (xd3_config *config) 1169main_set_secondary_flags (xd3_config *config)
1170{ 1170{
1171 int ret; 1171 int ret;
1172 if (option_use_secondary) 1172 if (!option_use_secondary)
1173 { 1173 {
1174 /* The default secondary compressor is DJW, if it's compiled. */ 1174 return 0;
1175 if (option_secondary == NULL) 1175 }
1176 if (option_secondary == NULL)
1177 {
1178 /* Set a default secondary compressor if LZMA is built in, otherwise
1179 * default to no secondary compressor. */
1180 if (SECONDARY_LZMA)
1176 { 1181 {
1177 if (SECONDARY_DJW) 1182 config->flags |= XD3_SEC_LZMA;
1178 {
1179 config->flags |= XD3_SEC_DJW;
1180 }
1181 } 1183 }
1182 else 1184 }
1185 else
1186 {
1187 if (strcmp (option_secondary, "lzma") == 0 && SECONDARY_LZMA)
1183 { 1188 {
1184 if (strcmp (option_secondary, "fgk") == 0 && SECONDARY_FGK) 1189 config->flags |= XD3_SEC_LZMA;
1185 { 1190 }
1186 config->flags |= XD3_SEC_FGK; 1191 else if (strcmp (option_secondary, "fgk") == 0 && SECONDARY_FGK)
1187 } 1192 {
1188 else if (strcmp (option_secondary, "lzma") == 0 && SECONDARY_LZMA) 1193 config->flags |= XD3_SEC_FGK;
1194 }
1195 else if (strncmp (option_secondary, "djw", 3) == 0 && SECONDARY_DJW)
1196 {
1197 usize_t level = XD3_DEFAULT_SECONDARY_LEVEL;
1198
1199 config->flags |= XD3_SEC_DJW;
1200
1201 if (strlen (option_secondary) > 3 &&
1202 (ret = main_atou (option_secondary + 3,
1203 &level,
1204 0, 9, 'S')) != 0 &&
1205 !option_quiet)
1189 { 1206 {
1190 config->flags |= XD3_SEC_LZMA; 1207 return XD3_INVALID;
1191 } 1208 }
1192 else if (strncmp (option_secondary, "djw", 3) == 0 && SECONDARY_DJW)
1193 {
1194 usize_t level = XD3_DEFAULT_SECONDARY_LEVEL;
1195 1209
1196 config->flags |= XD3_SEC_DJW; 1210 /* XD3_SEC_NOXXXX flags disable secondary compression on
1211 * a per-section basis. For djw, ngroups=1 indicates
1212 * minimum work, ngroups=0 uses default settings, which
1213 * is > 1 groups by default. */
1214 if (level < 1) { config->flags |= XD3_SEC_NODATA; }
1215 if (level < 7) { config->sec_data.ngroups = 1; }
1216 else { config->sec_data.ngroups = 0; }
1197 1217
1198 if (strlen (option_secondary) > 3 && 1218 if (level < 3) { config->flags |= XD3_SEC_NOINST; }
1199 (ret = main_atou (option_secondary + 3, 1219 if (level < 8) { config->sec_inst.ngroups = 1; }
1200 &level, 1220 else { config->sec_inst.ngroups = 0; }
1201 0, 9, 'S')) != 0 &&
1202 !option_quiet)
1203 {
1204 return XD3_INVALID;
1205 }
1206 1221
1207 /* XD3_SEC_NOXXXX flags disable secondary compression on 1222 if (level < 5) { config->flags |= XD3_SEC_NOADDR; }
1208 * a per-section basis. For djw, ngroups=1 indicates 1223 if (level < 9) { config->sec_addr.ngroups = 1; }
1209 * minimum work, ngroups=0 uses default settings, which 1224 else { config->sec_addr.ngroups = 0; }
1210 * is > 1 groups by default. */ 1225 }
1211 if (level < 1) { config->flags |= XD3_SEC_NODATA; } 1226 else if (*option_secondary == 0 ||
1212 if (level < 7) { config->sec_data.ngroups = 1; } 1227 strcmp (option_secondary, "none") == 0)
1213 else { config->sec_data.ngroups = 0; } 1228 {
1214 1229 }
1215 if (level < 3) { config->flags |= XD3_SEC_NOINST; } 1230 else
1216 if (level < 8) { config->sec_inst.ngroups = 1; } 1231 {
1217 else { config->sec_inst.ngroups = 0; } 1232 if (!option_quiet)
1218
1219 if (level < 5) { config->flags |= XD3_SEC_NOADDR; }
1220 if (level < 9) { config->sec_addr.ngroups = 1; }
1221 else { config->sec_addr.ngroups = 0; }
1222 }
1223 else if (strcmp (option_secondary, "none") == 0 && SECONDARY_DJW)
1224 {
1225 /* No secondary */
1226 }
1227 else
1228 { 1233 {
1229 if (!option_quiet) 1234 XPR(NT "unrecognized or not compiled secondary compressor: %s\n",
1230 { 1235 option_secondary);
1231 XPR(NT "unrecognized secondary compressor type: %s\n",
1232 option_secondary);
1233 return XD3_INVALID;
1234 }
1235 } 1236 }
1237 return XD3_INVALID;
1236 } 1238 }
1237 } 1239 }
1238 1240
@@ -2418,7 +2420,7 @@ main_secondary_decompress_check (main_file *file,
2418 usize_t i; 2420 usize_t i;
2419 usize_t try_read = xd3_min (input_size, XD3_ALLOCSIZE); 2421 usize_t try_read = xd3_min (input_size, XD3_ALLOCSIZE);
2420 size_t check_nread = 0; 2422 size_t check_nread = 0;
2421 uint8_t check_buf[XD3_ALLOCSIZE]; /* TODO: stack limit */ 2423 uint8_t check_buf[XD3_ALLOCSIZE]; /* TODO: heap allocate */
2422 const main_extcomp *decompressor = NULL; 2424 const main_extcomp *decompressor = NULL;
2423 2425
2424 if ((ret = main_file_read (file, check_buf, 2426 if ((ret = main_file_read (file, check_buf,
@@ -3354,7 +3356,8 @@ main_input (xd3_cmd cmd,
3354 default: 3356 default:
3355 /* input_func() error */ 3357 /* input_func() error */
3356 XPR(NT XD3_LIB_ERRMSG (& stream, ret)); 3358 XPR(NT XD3_LIB_ERRMSG (& stream, ret));
3357 if (! option_quiet && ret == XD3_INVALID_INPUT) 3359 if (! option_quiet && ret == XD3_INVALID_INPUT &&
3360 sfile != NULL && sfile->filename != NULL)
3358 { 3361 {
3359 XPR(NT "normally this indicates that the source file is incorrect\n"); 3362 XPR(NT "normally this indicates that the source file is incorrect\n");
3360 XPR(NT "please verify the source file with sha1sum or equivalent\n"); 3363 XPR(NT "please verify the source file with sha1sum or equivalent\n");
@@ -3759,8 +3762,8 @@ int main (int argc, char **argv)
3759 case 'J': option_no_output = 1; break; 3762 case 'J': option_no_output = 1; break;
3760 case 'S': if (my_optarg == NULL) 3763 case 'S': if (my_optarg == NULL)
3761 { 3764 {
3762 option_use_secondary = 1; 3765 option_use_secondary = 0;
3763 option_secondary = "none"; 3766 option_secondary = NULL;
3764 } 3767 }
3765 else 3768 else
3766 { 3769 {
diff --git a/xdelta3/xdelta3-second.h b/xdelta3/xdelta3-second.h
index 098a5d5..309c947 100644
--- a/xdelta3/xdelta3-second.h
+++ b/xdelta3/xdelta3-second.h
@@ -140,6 +140,12 @@ xd3_decode_secondary (xd3_stream *stream,
140 return ret; 140 return ret;
141 } 141 }
142 142
143 if (dec_size == 0)
144 {
145 stream->msg = "secondary decoder invalid output size";
146 return XD3_INVALID_INPUT;
147 }
148
143 out_used = sect->copied2; 149 out_used = sect->copied2;
144 150
145 if ((ret = stream->sec_type->decode (stream, *sec_streamp, 151 if ((ret = stream->sec_type->decode (stream, *sec_streamp,
diff --git a/xdelta3/xdelta3-test.h b/xdelta3/xdelta3-test.h
index d7cb48e..ddbfd65 100644
--- a/xdelta3/xdelta3-test.h
+++ b/xdelta3/xdelta3-test.h
@@ -236,7 +236,8 @@ static void
236test_unlink (char* file) 236test_unlink (char* file)
237{ 237{
238 int ret; 238 int ret;
239 if ((ret = unlink (file)) != 0 && errno != ENOENT) 239 if (file != NULL && *file != 0 &&
240 (ret = unlink (file)) != 0 && errno != ENOENT)
240 { 241 {
241 XPR(NT "unlink %s failed: %s\n", file, strerror(ret)); 242 XPR(NT "unlink %s failed: %s\n", file, strerror(ret));
242 } 243 }
@@ -261,6 +262,9 @@ int test_setup (void)
261 static int x = 0; 262 static int x = 0;
262 pid_t pid = getpid(); 263 pid_t pid = getpid();
263 x++; 264 x++;
265
266 test_cleanup();
267
264 snprintf_func (TEST_TARGET_FILE, TESTFILESIZE, 268 snprintf_func (TEST_TARGET_FILE, TESTFILESIZE,
265 "/tmp/xdtest.%d.target.%d", pid, x); 269 "/tmp/xdtest.%d.target.%d", pid, x);
266 snprintf_func (TEST_SOURCE_FILE, TESTFILESIZE, 270 snprintf_func (TEST_SOURCE_FILE, TESTFILESIZE,
@@ -275,6 +279,7 @@ int test_setup (void)
275 "/tmp/xdtest.%d.copy.%d", pid, x); 279 "/tmp/xdtest.%d.copy.%d", pid, x);
276 snprintf_func (TEST_NOPERM_FILE, TESTFILESIZE, 280 snprintf_func (TEST_NOPERM_FILE, TESTFILESIZE,
277 "/tmp/xdtest.%d.noperm.%d", pid, x); 281 "/tmp/xdtest.%d.noperm.%d", pid, x);
282
278 test_cleanup(); 283 test_cleanup();
279 return 0; 284 return 0;
280} 285}
@@ -1516,7 +1521,8 @@ IF_DJW (static int test_secondary_huff (xd3_stream *stream, usize_t gp)
1516 { return test_secondary (stream, & djw_sec_type, gp); }) 1521 { return test_secondary (stream, & djw_sec_type, gp); })
1517IF_LZMA (static int test_secondary_lzma (xd3_stream *stream, usize_t gp) 1522IF_LZMA (static int test_secondary_lzma (xd3_stream *stream, usize_t gp)
1518 { return test_secondary (stream, & lzma_sec_type, gp); }) 1523 { return test_secondary (stream, & lzma_sec_type, gp); })
1519#endif 1524
1525#endif /* SECONDARY_ANY */
1520 1526
1521/*********************************************************************** 1527/***********************************************************************
1522 TEST INSTRUCTION TABLE 1528 TEST INSTRUCTION TABLE
@@ -1952,7 +1958,7 @@ test_recode_command2 (xd3_stream *stream, int has_source,
1952 recoded_adler32 ? "" : "-n ", 1958 recoded_adler32 ? "" : "-n ",
1953 !change_apphead ? "" : 1959 !change_apphead ? "" :
1954 (recoded_apphead ? "-A=recode_apphead " : "-A= "), 1960 (recoded_apphead ? "-A=recode_apphead " : "-A= "),
1955 recoded_secondary ? "-S djw " : "-S none ", 1961 recoded_secondary ? "-S djw " : "-S= ",
1956 TEST_DELTA_FILE, 1962 TEST_DELTA_FILE,
1957 TEST_COPY_FILE); 1963 TEST_COPY_FILE);
1958 1964
@@ -2048,6 +2054,7 @@ test_recode_command2 (xd3_stream *stream, int has_source,
2048 { 2054 {
2049 return ret; 2055 return ret;
2050 } 2056 }
2057 test_cleanup ();
2051 2058
2052 return 0; 2059 return 0;
2053} 2060}
@@ -2086,7 +2093,46 @@ test_recode_command (xd3_stream *stream, int ignore)
2086 2093
2087 return 0; 2094 return 0;
2088} 2095}
2089#endif 2096
2097#if SECONDARY_LZMA
2098int test_secondary_lzma_default (xd3_stream *stream, int ignore)
2099{
2100 char ecmd[TESTBUFSIZE];
2101 int ret;
2102
2103 test_setup ();
2104
2105 if ((ret = test_make_inputs (stream, NULL, NULL)))
2106 {
2107 return ret;
2108 }
2109
2110 /* First encode */
2111 snprintf_func (ecmd, TESTBUFSIZE, "%s -e %s %s",
2112 program_name,
2113 TEST_TARGET_FILE,
2114 TEST_DELTA_FILE);
2115
2116 if ((ret = system (ecmd)) != 0)
2117 {
2118 return XD3_INTERNAL;
2119 }
2120
2121 if ((ret = check_vcdiff_header (stream,
2122 TEST_DELTA_FILE,
2123 "VCDIFF secondary compressor",
2124 "lzma",
2125 1)))
2126 {
2127 return ret;
2128 }
2129
2130 test_cleanup ();
2131 return 0;
2132}
2133
2134#endif /* SECONDARY_LZMA */
2135#endif /* SHELL_TESTS */
2090 2136
2091/*********************************************************************** 2137/***********************************************************************
2092 EXTERNAL I/O DECOMPRESSION/RECOMPRESSION 2138 EXTERNAL I/O DECOMPRESSION/RECOMPRESSION
@@ -2468,6 +2514,7 @@ test_appheader (xd3_stream *stream, int ignore)
2468 return XD3_INVALID; // Must have crashed! 2514 return XD3_INVALID; // Must have crashed!
2469 } 2515 }
2470 2516
2517 test_cleanup ();
2471 return 0; 2518 return 0;
2472} 2519}
2473 2520
@@ -2964,6 +3011,7 @@ int xd3_selftest (void)
2964 DO_TEST (recode_command, 0, 0); 3011 DO_TEST (recode_command, 0, 0);
2965#endif 3012#endif
2966 3013
3014 IF_LZMA (DO_TEST (secondary_lzma_default, 0, 0));
2967 IF_LZMA (DO_TEST (secondary_lzma, 0, 1)); 3015 IF_LZMA (DO_TEST (secondary_lzma, 0, 1));
2968 IF_DJW (DO_TEST (secondary_huff, 0, DJW_MAX_GROUPS)); 3016 IF_DJW (DO_TEST (secondary_huff, 0, DJW_MAX_GROUPS));
2969 IF_FGK (DO_TEST (secondary_fgk, 0, 1)); 3017 IF_FGK (DO_TEST (secondary_fgk, 0, 1));
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c
index 874b35a..d95d97d 100644
--- a/xdelta3/xdelta3.c
+++ b/xdelta3/xdelta3.c
@@ -1598,8 +1598,11 @@ xd3_free_stream (xd3_stream *stream)
1598 xd3_free (stream, stream->addr_sect.copied1); 1598 xd3_free (stream, stream->addr_sect.copied1);
1599 xd3_free (stream, stream->data_sect.copied1); 1599 xd3_free (stream, stream->data_sect.copied1);
1600 1600
1601 if (stream->dec_lastwin != stream->dec_buffer)
1602 {
1603 xd3_free (stream, (uint8_t*) stream->dec_lastwin);
1604 }
1601 xd3_free (stream, stream->dec_buffer); 1605 xd3_free (stream, stream->dec_buffer);
1602 xd3_free (stream, (uint8_t*) stream->dec_lastwin);
1603 1606
1604 xd3_free (stream, stream->buf_in); 1607 xd3_free (stream, stream->buf_in);
1605 xd3_free (stream, stream->dec_appheader); 1608 xd3_free (stream, stream->dec_appheader);
diff --git a/xdelta3/xdelta3.prj b/xdelta3/xdelta3.prj
deleted file mode 100644
index 96c3a8c..0000000
--- a/xdelta3/xdelta3.prj
+++ /dev/null
@@ -1,61 +0,0 @@
1;; -*- Prcs -*-
2(Created-By-Prcs-Version 1 3 4)
3(Project-Description "")
4(Project-Version xdelta3 0 35)
5(Parent-Version xdelta3 0 34)
6(Version-Log "3.0r Removes NODECOMPRESSIZE")
7(New-Version-Log "")
8(Checkin-Time "Wed, 10 Oct 2007 02:27:56 -0700")
9(Checkin-Login jmacd)
10(Populate-Ignore ("\\.svn"))
11(Project-Keywords
12 (Xdelta3Version "3.0.10")
13 )
14(Files
15 (COPYING (xdelta3/b/29_COPYING 1.1 744))
16
17 (xdelta3-cfgs.h (xdelta3/9_xdelta3-cf 1.8 744))
18 (xdelta3-decode.h (xdelta3/b/30_xdelta3-de 1.7 744))
19 (xdelta3-djw.h (xdelta3/8_xdelta3-dj 1.8 744))
20 (xdelta3-fgk.h (xdelta3/7_xdelta3-fg 1.4 744))
21 (xdelta3-list.h (xdelta3/6_xdelta3-li 1.3 744))
22 (xdelta3-main.h (xdelta3/5_xdelta3-ma 1.21 744))
23 (xdelta3-python.h (xdelta3/4_xdelta3-py 1.5 744))
24 (xdelta3-regtest.py (xdelta3/10_xdelta3-re 1.20 744))
25 (xdelta3-second.h (xdelta3/3_xdelta3-se 1.6 744))
26 (xdelta3-test.h (xdelta3/2_xdelta3-te 1.16 744))
27 (xdelta3.c (xdelta3/16_xdelta3.c 1.19 744))
28 (xdelta3.h (xdelta3/1_xdelta3.h 1.17 744))
29
30 (Makefile (xdelta3/0_Makefile 1.13 744))
31 (setup.py (xdelta3/11_setup.py 1.5 744))
32
33 (draft-korn-vcdiff.txt (xdelta3/b/22_draft-korn 1.1 744))
34
35 (badcopy.c (xdelta3/20_badcopy.c 1.2 744))
36 (linkxd3lib.c (xdelta3/19_linkxd3lib 1.3 744))
37 (rcs_junk.cc (xdelta3/15_rcs_junk.c 1.1 744))
38
39 (README (xdelta3/b/31_README 1.1 744))
40 (badcopy.vcproj (xdelta3/b/32_badcopy.vc 1.1 744))
41 (xdelta3.vcproj (xdelta3/b/33_xdelta3.vc 1.4 744))
42
43 (xdelta3.swig (xdelta3/b/27_xdelta3.sw 1.3 744))
44
45 (xdelta3-test.py (xdelta3/b/28_xdelta3-te 1.5 744))
46
47 (examples/Makefile (xdelta3/b/34_Makefile 1.2 744))
48 (examples/small_page_test.c (xdelta3/b/35_small_page 1.2 744))
49
50 (plot.sh (xdelta3/b/36_plot.sh 1.1 744))
51
52 (xdelta3.wxs (xdelta3/b/37_xdelta3.wx 1.1 744))
53 (xdelta3.wxi (xdelta3/b/38_xdelta3.wx 1.1 744))
54
55;; Files added by populate at Wed, 10 Oct 2007 02:15:48 -0700,
56;; to version 0.33(w), by jmacd:
57
58 (examples/encode_decode_test.c (xdelta3/b/39_encode_dec 1.1 744))
59)
60(Merge-Parents)
61(New-Merge-Parents)