You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by rh...@apache.org on 2013/10/30 18:28:33 UTC

svn commit: r1537193 - in /subversion/trunk/subversion/tests/libsvn_subr: checksum-test.c zlib.deflated

Author: rhuijben
Date: Wed Oct 30 17:28:33 2013
New Revision: 1537193

URL: http://svn.apache.org/r1537193
Log:
Add regression test for the ZLib decompression problem identified in
ZLib 1.2.8 with assembly optimizations enabled.

This should make it easier for packagers to find out if they need to
fix their installation.

* subversion/tests/libsvn_subr/checksum-test.c
  (includes): Add zlib.h and svn_io.h.
  (zlib_expansion_test): New function.
  (test_funcs): Add zlib_expansion_test.

* subversion/tests/libsvn_subr/zlib.deflated
  Add the compressed version of an old Subversion CHANGES file that showcased
  the original compression problem.

Added:
    subversion/trunk/subversion/tests/libsvn_subr/zlib.deflated   (with props)
Modified:
    subversion/trunk/subversion/tests/libsvn_subr/checksum-test.c

Modified: subversion/trunk/subversion/tests/libsvn_subr/checksum-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/checksum-test.c?rev=1537193&r1=1537192&r2=1537193&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/checksum-test.c (original)
+++ subversion/trunk/subversion/tests/libsvn_subr/checksum-test.c Wed Oct 30 17:28:33 2013
@@ -23,7 +23,10 @@
 
 #include <apr_pools.h>
 
+#include <zlib.h>
+
 #include "svn_error.h"
+#include "svn_io.h"
 #include "private/svn_pseudo_md5.h"
 
 #include "../svn_test.h"
@@ -155,6 +158,91 @@ zero_match(apr_pool_t *pool)
   return SVN_NO_ERROR;
 }
 
+static svn_error_t *
+zlib_expansion_test(const svn_test_opts_t *opts,
+                    apr_pool_t *pool)
+{
+  const char *data_path;
+  svn_stringbuf_t *deflated;
+  Byte dst_buffer[256 * 1024];
+  Byte *src_buffer;
+  apr_size_t sz;
+
+  data_path = svn_dirent_join(opts->srcdir, "zlib.deflated", pool);
+
+  SVN_ERR(svn_stringbuf_from_file2(&deflated, data_path, pool));
+  src_buffer = (Byte*)deflated->data;
+
+  z_stream stream;
+  memset(&stream, 0, sizeof(stream));
+  inflateInit2(&stream, -15 /* DEFLATE_WINDOW_SIZE */);
+
+  /* Try to decompress the same data with different blocksizes */
+  for (sz = 1; sz < 256; sz++)
+    {
+      z_stream stream;
+      memset(&stream, 0, sizeof(stream));
+      inflateInit2(&stream, -15 /* DEFLATE_WINDOW_SIZE */);
+
+      stream.avail_in = sz;
+      stream.next_in = src_buffer;
+      stream.avail_out = sizeof(dst_buffer);
+      stream.next_out = dst_buffer;
+
+      do
+        {
+          int zr = inflate(&stream, Z_NO_FLUSH);
+
+          if (zr != Z_OK && zr != Z_STREAM_END)
+          {
+              return svn_error_createf(
+                          SVN_ERR_TEST_FAILED, NULL,
+                          "Failure decompressing with blocksize %d", (int)sz);
+          }
+          stream.avail_in += sz;
+      } while (stream.next_in + stream.avail_in  < src_buffer + deflated->len);
+
+      stream.avail_in = (src_buffer + deflated->len) - stream.next_in;
+
+      {
+          int zr = inflate(&stream, Z_NO_FLUSH);
+
+          if (zr != Z_STREAM_END)
+            {
+              return svn_error_createf(
+                        SVN_ERR_TEST_FAILED, NULL,
+                        "Final flush failed with blocksize %d", (int)sz);
+            }
+
+          zr = inflateEnd(&stream);
+
+          if (zr != Z_OK)
+            {
+              return svn_error_createf(
+                        SVN_ERR_TEST_FAILED, NULL,
+                        "End of stream handling failed with blocksize %d",
+                        (int)sz);
+            }
+      }
+
+      {
+          apr_uint32_t crc = crc32(0, dst_buffer, stream.total_out);
+
+          if (stream.total_out != 242014 || crc != 0x8f03d934)
+            {
+              return svn_error_createf(
+                  SVN_ERR_TEST_FAILED, NULL,
+                  "Decompressed data doesn't match expected size or crc with "
+                  "blocksize %d: Found crc32=0x%08x, size=%d.\n"
+                  "Verify your ZLib installation, as this should never happen",
+                  (int)sz, (unsigned)crc, (int)stream.total_out);
+            }
+      }
+  }
+
+  return SVN_NO_ERROR;
+}
+
 /* An array of all test functions */
 struct svn_test_descriptor_t test_funcs[] =
   {
@@ -167,5 +255,7 @@ struct svn_test_descriptor_t test_funcs[
                    "pseudo-md5 compatibility"),
     SVN_TEST_PASS2(zero_match,
                    "zero checksum matching"),
+    SVN_TEST_OPTS_PASS(zlib_expansion_test,
+                       "zlib expansion test (zlib regression)"),
     SVN_TEST_NULL
   };

Added: subversion/trunk/subversion/tests/libsvn_subr/zlib.deflated
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_subr/zlib.deflated?rev=1537193&view=auto
==============================================================================
Binary file - no diff available.

Propchange: subversion/trunk/subversion/tests/libsvn_subr/zlib.deflated
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream