[ccache] ccache doesn't notice gzip CRC errors

Wilson Snyder wsnyder at wsnyder.org
Thu Oct 28 19:54:08 MDT 2010

GZIP files contain CRC checksums, however ccache doesn't
notice CRC errors because it doesn't check gzerror at the
end of decompression.  This patch fixes it.  (It's arguably
a bad API decision on the gz library's part, but we're stuck
with it.)


diff --git a/util.c b/util.c
index 58723f0..f2ad77c 100644
--- a/util.c
+++ b/util.c
@@ -284,7 +284,12 @@ copy_file(const char *src, const char *dest, int compress_dest)
 			goto error;
-	if (n == 0 && !gzeof(gz_in)) {
+	/* gzeof won't tell if there's an error in the trailing crc,
+	   so must gzeof then test gzerror before considering everything ok */
+	gzeof(gz_in);
+	gzerror(gz_in, &errnum);
+	if (!gzeof(gz_in) || (errnum != Z_OK && errnum != Z_STREAM_END)) {
 		cc_log("gzread error: %s (errno: %s)",
 		       gzerror(gz_in, &errnum), strerror(errno));

More information about the ccache mailing list