Skip to content

Commit 4d2dd0b

Browse files
libbacktrace: don't skip initial aligned byte in uncompressed block
Patch from Rui Ueyama, who says: libbacktrace occasionally fails to decompress compressed debug info even though the sections contain valid zlib streams. The cause of the issue is an off-by-one error. If a zlib data block is a plain data (uncompressed data), the next two bytes contain the size of the block. These two bytes value is byte- aligned, so if we read-ahead more than 8 bits, we need to unread it. So, the correct condition to determine whether or not we need to unread a byte is bits >= 8 and not bits > 8. Due to this error, if the last read bits happened to end at a byte boundary, the next byte would be skipped. That caused the decompression failure. This bug was originally reported against the mold linker. rui314/mold#402 * elf.c (elf_zlib_inflate): Don't skip initial aligned byte in uncompressed block.
1 parent 2446c66 commit 4d2dd0b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

elf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,7 @@ elf_zlib_inflate (const unsigned char *pin, size_t sin, uint16_t *zdebug_table,
17961796
/* An uncompressed block. */
17971797

17981798
/* If we've read ahead more than a byte, back up. */
1799-
while (bits > 8)
1799+
while (bits >= 8)
18001800
{
18011801
--pin;
18021802
bits -= 8;

0 commit comments

Comments
 (0)