lib/lzo: fix ambiguous encoding bug in lzo-rle
[linux-2.6-microblaze.git] / lib / lzo / lzo1x_compress.c
index 717c940..8ad5ba2 100644 (file)
@@ -268,6 +268,19 @@ m_len_done:
                                *op++ = (M4_MARKER | ((m_off >> 11) & 8)
                                                | (m_len - 2));
                        else {
+                               if (unlikely(((m_off & 0x403f) == 0x403f)
+                                               && (m_len >= 261)
+                                               && (m_len <= 264))
+                                               && likely(bitstream_version)) {
+                                       // Under lzo-rle, block copies
+                                       // for 261 <= length <= 264 and
+                                       // (distance & 0x80f3) == 0x80f3
+                                       // can result in ambiguous
+                                       // output. Adjust length
+                                       // to 260 to prevent ambiguity.
+                                       ip -= m_len - 260;
+                                       m_len = 260;
+                               }
                                m_len -= M4_MAX_LEN;
                                *op++ = (M4_MARKER | ((m_off >> 11) & 8));
                                while (unlikely(m_len > 255)) {