[tor-commits] [tor/master] Remove support for zlib <= 1.1

nickm at torproject.org nickm at torproject.org
Sun Jun 19 16:22:38 UTC 2016


commit 808015316a5680003b78393c50b0701c47e1051c
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed Jun 8 18:14:51 2016 -0400

    Remove support for zlib <= 1.1
    
    zlib 1.2 came out in 2003; earlier versions should be dead by now.
    
    Our workaround code was only preventing us from using the gzip
    encoding (if we decide to do so), and having some dead code linger
    around in torgzip.c
---
 changes/zlib_12      |  4 ++++
 src/common/torgzip.c | 44 ++++----------------------------------------
 src/test/test_util.c |  3 ++-
 3 files changed, 10 insertions(+), 41 deletions(-)

diff --git a/changes/zlib_12 b/changes/zlib_12
new file mode 100644
index 0000000..3344286
--- /dev/null
+++ b/changes/zlib_12
@@ -0,0 +1,4 @@
+  o New system requirements:
+    - We now require zlib version 1.2 or later. (Back when we started,
+      zlib 1.1 and zlib 1.0 were still found in the wild. 1.2 was released in
+      2003. We recommend the latest version.)
diff --git a/src/common/torgzip.c b/src/common/torgzip.c
index 71e55f8..57994c4 100644
--- a/src/common/torgzip.c
+++ b/src/common/torgzip.c
@@ -46,34 +46,16 @@
 
 #include <zlib.h>
 
+#if defined ZLIB_VERNUM && ZLIB_VERNUM < 0x1200
+#error "We require zlib version 1.2 or later."
+#endif
+
 static size_t tor_zlib_state_size_precalc(int inflate,
                                           int windowbits, int memlevel);
 
 /** Total number of bytes allocated for zlib state */
 static size_t total_zlib_allocation = 0;
 
-/** Set to 1 if zlib is a version that supports gzip; set to 0 if it doesn't;
- * set to -1 if we haven't checked yet. */
-static int gzip_is_supported = -1;
-
-/** Return true iff we support gzip-based compression.  Otherwise, we need to
- * use zlib. */
-int
-is_gzip_supported(void)
-{
-  if (gzip_is_supported >= 0)
-    return gzip_is_supported;
-
-  if (!strcmpstart(ZLIB_VERSION, "0.") ||
-      !strcmpstart(ZLIB_VERSION, "1.0") ||
-      !strcmpstart(ZLIB_VERSION, "1.1"))
-    gzip_is_supported = 0;
-  else
-    gzip_is_supported = 1;
-
-  return gzip_is_supported;
-}
-
 /** Return a string representation of the version of the currently running
  * version of zlib. */
 const char *
@@ -165,12 +147,6 @@ tor_gzip_compress(char **out, size_t *out_len,
 
   *out = NULL;
 
-  if (method == GZIP_METHOD && !is_gzip_supported()) {
-    /* Old zlib version don't support gzip in deflateInit2 */
-    log_warn(LD_BUG, "Gzip not supported with zlib %s", ZLIB_VERSION);
-    goto err;
-  }
-
   stream = tor_malloc_zero(sizeof(struct z_stream_s));
   stream->zalloc = Z_NULL;
   stream->zfree = Z_NULL;
@@ -291,12 +267,6 @@ tor_gzip_uncompress(char **out, size_t *out_len,
   tor_assert(in);
   tor_assert(in_len < UINT_MAX);
 
-  if (method == GZIP_METHOD && !is_gzip_supported()) {
-    /* Old zlib version don't support gzip in inflateInit2 */
-    log_warn(LD_BUG, "Gzip not supported with zlib %s", ZLIB_VERSION);
-    return -1;
-  }
-
   *out = NULL;
 
   stream = tor_malloc_zero(sizeof(struct z_stream_s));
@@ -451,12 +421,6 @@ tor_zlib_new(int compress, compress_method_t method,
   tor_zlib_state_t *out;
   int bits, memlevel;
 
-  if (method == GZIP_METHOD && !is_gzip_supported()) {
-    /* Old zlib version don't support gzip in inflateInit2 */
-    log_warn(LD_BUG, "Gzip not supported with zlib %s", ZLIB_VERSION);
-    return NULL;
- }
-
  if (! compress) {
    /* use this setting for decompression, since we might have the
     * max number of window bits */
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 8b9d5ea..204d5db 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -1737,7 +1737,8 @@ test_util_gzip(void *arg)
   (void)arg;
   buf1 = tor_strdup("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZAAAAAAAAAAAAAAAAAAAZ");
   tt_assert(detect_compression_method(buf1, strlen(buf1)) == UNKNOWN_METHOD);
-  if (is_gzip_supported()) {
+
+  if (1) {
     tt_assert(!tor_gzip_compress(&buf2, &len1, buf1, strlen(buf1)+1,
                                    GZIP_METHOD));
     tt_assert(buf2);





More information about the tor-commits mailing list