Cyril Brulebois <k...@debian.org> (08/02/2012): > Playing on amd64: > cbrulebois@Cygnus:/tmp/ppl-0.11.2$ cp ../ppl-pristine/{CREDITS,README} . > cbrulebois@Cygnus:/tmp/ppl-0.11.2$ gzip -9nf CREDITS README > cbrulebois@Cygnus:/tmp/ppl-0.11.2$ ls -l *gz > -rw-r--r-- 1 cbrulebois cbrulebois 6343 Feb 8 12:34 CREDITS.gz > -rw-r--r-- 1 cbrulebois cbrulebois 8745 Feb 8 12:34 README.gz > cbrulebois@Cygnus:/tmp/ppl-0.11.2$ cp ../ppl-pristine/{CREDITS,README} . > cbrulebois@Cygnus:/tmp/ppl-0.11.2$ gzip -9nf README CREDITS > cbrulebois@Cygnus:/tmp/ppl-0.11.2$ ls -l *gz > -rw-r--r-- 1 cbrulebois cbrulebois 6344 Feb 8 12:34 CREDITS.gz > -rw-r--r-- 1 cbrulebois cbrulebois 8745 Feb 8 12:34 README.gz > > It looks to me like it shouldn't be hard to figure out what happens here > given the few tests I performed with the above command lines. On a few > iterations, reproducibility (with a given input command line) doesn't > seem to be an issue.
I think at least the attached patch won't hurt (when the DYN_ALLOC part is fixed; and possibly turning that into a MEMSET-like macro). And given dh_compress is passing files in an arbitrary order (it's using “find” to detect files which needs to be compressed), I think we have an explanation about the apparently-hard-to-reproduce issues. Mraw, KiBi.
diff --git a/gzip.c b/gzip.c index b867350..1153bde 100644 --- a/gzip.c +++ b/gzip.c @@ -561,6 +561,19 @@ int main (int argc, char **argv) SET_BINARY_MODE(fileno(stdout)); } while (optind < argc) { + + /* Make sure buffers are reset to 0 to ensure reproducibility when handling several files */ + ZEROIFY(uch, inbuf, INBUFSIZ +INBUF_EXTRA); + ZEROIFY(uch, outbuf, OUTBUFSIZ+OUTBUF_EXTRA); + ZEROIFY(ush, d_buf, DIST_BUFSIZE); + ZEROIFY(uch, window, 2L*WSIZE); +#ifndef MAXSEG_64K + ZEROIFY(ush, tab_prefix, 1L<<BITS); +#else + ZEROIFY(ush, tab_prefix0, 1L<<(BITS-1)); + ZEROIFY(ush, tab_prefix1, 1L<<(BITS-1)); +#endif + treat_file(argv[optind++]); } } else { /* Standard input */ diff --git a/gzip.h b/gzip.h index 5270c56..7a1e84b 100644 --- a/gzip.h +++ b/gzip.h @@ -119,11 +119,13 @@ extern int method; /* compression method */ array = (type*)fcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \ if (!array) xalloc_die (); \ } +# error "ZEROIFY needs an implementation, KiBi is lazy" # define FREE(array) {if (array != NULL) fcfree(array), array=NULL;} #else # define EXTERN(type, array) extern type array[] # define DECLARE(type, array, size) type array[size] # define ALLOC(type, array, size) +# define ZEROIFY(type, array, size) { for (int i=0; i<size; i++) { array[i] = 0; } } # define FREE(array) #endif
signature.asc
Description: Digital signature