]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
lib/lzo: Do not leak implementation details in lzo1x_1_compress()
authorMarkus F.X.J. Oberhumer <markus@oberhumer.com>
Thu, 18 Oct 2012 02:35:32 +0000 (04:35 +0200)
committerMarkus F.X.J. Oberhumer <markus@oberhumer.com>
Thu, 18 Oct 2012 02:35:32 +0000 (04:35 +0200)
The previous compressor version could produce slightly different (but
of course valid) compressed data representations, depending on
implementation details like CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS.

Avoid that by synchronizing (partial unrolling) all affected code paths.

This update also allows backing out the previous testvector input change.

Signed-off-by: Markus F.X.J. Oberhumer <markus@oberhumer.com>
crypto/testmgr.h
lib/lzo/lzo1x_compress.c

index 3990d1310b5fbe2796bc48f2c34c5c60354d4059..1ae2e0ea5492c8a65604a038aec782ebfccb2979 100644 (file)
@@ -14557,26 +14557,24 @@ static struct pcomp_testvec zlib_decomp_tv_template[] = {
 
 static struct comp_testvec lzo_comp_tv_template[] = {
        {
-               .inlen  = 96,
-               .outlen = 70,
+               .inlen  = 70,
+               .outlen = 57,
                .input  = "Join us now and share the software "
-                       "Join us now and share the software "
-                       "abcdefghijklmnopqrstuvwxyz",
+                       "Join us now and share the software ",
                .output = "\x00\x0d\x4a\x6f\x69\x6e\x20\x75"
                          "\x73\x20\x6e\x6f\x77\x20\x61\x6e"
                          "\x64\x20\x73\x68\x61\x72\x65\x20"
                          "\x74\x68\x65\x20\x73\x6f\x66\x74"
-                         "\x77\x70\x01\x20\x02\x88\x00\x00"
-                         "\x08\x61\x62\x63\x64\x65\x66\x67"
-                         "\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f"
-                         "\x70\x71\x72\x73\x74\x75\x76\x77"
-                         "\x78\x79\x7a\x11\x00\x00",
+                         "\x77\x70\x01\x32\x88\x00\x0c\x65"
+                         "\x20\x74\x68\x65\x20\x73\x6f\x66"
+                         "\x74\x77\x61\x72\x65\x20\x11\x00"
+                         "\x00",
        }, {
-               .inlen  = 185,
-               .outlen = 158,
+               .inlen  = 159,
+               .outlen = 131,
                .input  = "This document describes a compression method based on the LZO "
                        "compression algorithm.  This document defines the application of "
-                       "the LZO algorithm used in UBIFS.abcdefghijklmnopqrstuvwxyz",
+                       "the LZO algorithm used in UBIFS.",
                .output = "\x00\x2c\x54\x68\x69\x73\x20\x64"
                          "\x6f\x63\x75\x6d\x65\x6e\x74\x20"
                          "\x64\x65\x73\x63\x72\x69\x62\x65"
@@ -14591,12 +14589,9 @@ static struct comp_testvec lzo_comp_tv_template[] = {
                          "\x73\x20\x74\x06\x05\x61\x70\x70"
                          "\x6c\x69\x63\x61\x74\x76\x0a\x6f"
                          "\x66\x88\x02\x60\x09\x27\xf0\x00"
-                         "\x00\x17\x20\x75\x73\x65\x64\x20"
-                         "\x69\x6e\x20\x55\x42\x49\x46\x53"
-                         "\x2e\x61\x62\x63\x64\x65\x66\x67"
-                         "\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f"
-                         "\x70\x71\x72\x73\x74\x75\x76\x77"
-                         "\x78\x79\x7a\x11\x00\x00",
+                         "\x0c\x20\x75\x73\x65\x64\x20\x69"
+                         "\x6e\x20\x55\x42\x49\x46\x53\x2e"
+                         "\x11\x00\x00",
        },
 };
 
index 1593dbae4a50832b89d81a66399ec4b5c8c551f2..236eb21167b5db1f5cd542efbf6c66dd770455fc 100644 (file)
@@ -117,6 +117,11 @@ next:
                if (unlikely(v == 0)) {
                        do {
                                m_len += 4;
+                               v = get_unaligned((const u32 *) (ip + m_len)) ^
+                                   get_unaligned((const u32 *) (m_pos + m_len));
+                               if (v != 0)
+                                       break;
+                               m_len += 4;
                                v = get_unaligned((const u32 *) (ip + m_len)) ^
                                    get_unaligned((const u32 *) (m_pos + m_len));
                                if (unlikely(ip + m_len >= ip_end))
@@ -134,6 +139,27 @@ next:
                if (unlikely(ip[m_len] == m_pos[m_len])) {
                        do {
                                m_len += 1;
+                               if (ip[m_len] != m_pos[m_len])
+                                       break;
+                               m_len += 1;
+                               if (ip[m_len] != m_pos[m_len])
+                                       break;
+                               m_len += 1;
+                               if (ip[m_len] != m_pos[m_len])
+                                       break;
+                               m_len += 1;
+                               if (ip[m_len] != m_pos[m_len])
+                                       break;
+                               m_len += 1;
+                               if (ip[m_len] != m_pos[m_len])
+                                       break;
+                               m_len += 1;
+                               if (ip[m_len] != m_pos[m_len])
+                                       break;
+                               m_len += 1;
+                               if (ip[m_len] != m_pos[m_len])
+                                       break;
+                               m_len += 1;
                                if (unlikely(ip + m_len >= ip_end))
                                        goto m_len_done;
                        } while (ip[m_len] == m_pos[m_len]);