lzx-decompress.c: Fix alignment bug
authorEric Biggers <ebiggers3@gmail.com>
Sat, 12 Oct 2013 00:11:41 +0000 (19:11 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Sat, 12 Oct 2013 00:15:58 +0000 (19:15 -0500)
The pretree decode table was not declared to be 16 byte aligned, as
expected by make_huffman_decode_table().

This bug had no effect if the compiler aligned this table on a 16 byte
boundary anyway, but if not it caused a segmentation fault on x86 platforms
where the SSE2 instructions were available, since in that case stores
requiring 16 byte alignment are used to fill in table entries.

src/decompress.c
src/lzx-decompress.c

index 1ef8823..227bfb0 100644 (file)
@@ -53,7 +53,8 @@
  * @decode_table:      The array in which to create the fast huffman decoding
  *                     table.  It must have a length of at least
  *                     (2**table_bits) + 2 * num_syms to guarantee
  * @decode_table:      The array in which to create the fast huffman decoding
  *                     table.  It must have a length of at least
  *                     (2**table_bits) + 2 * num_syms to guarantee
- *                     that there is enough space.
+ *                     that there is enough space.  Also must be 16-byte
+ *                     aligned (at least when USE_SSE2_FILL gets defined).
  *
  * @num_syms:          Number of symbols in the alphabet, including symbols
  *                     that do not appear in this particular input chunk.
  *
  * @num_syms:          Number of symbols in the alphabet, including symbols
  *                     that do not appear in this particular input chunk.
index 99502d4..a24b083 100644 (file)
@@ -204,7 +204,8 @@ lzx_read_code_lens(struct input_bitstream *istream, u8 lens[],
 {
        /* Declare the decoding table and length table for the pretree. */
        u16 pretree_decode_table[(1 << LZX_PRETREE_TABLEBITS) +
 {
        /* Declare the decoding table and length table for the pretree. */
        u16 pretree_decode_table[(1 << LZX_PRETREE_TABLEBITS) +
-                                       (LZX_PRETREE_NUM_SYMBOLS * 2)];
+                                       (LZX_PRETREE_NUM_SYMBOLS * 2)]
+                                       _aligned_attribute(DECODE_TABLE_ALIGNMENT);
        u8 pretree_lens[LZX_PRETREE_NUM_SYMBOLS];
        unsigned i;
        unsigned len;
        u8 pretree_lens[LZX_PRETREE_NUM_SYMBOLS];
        unsigned i;
        unsigned len;