Skip to content

Commit

Permalink
Decompressors: check for read errors in decompress_unlzma.c
Browse files Browse the repository at this point in the history
Return value of rc->fill() is checked in rc_read() and error() is called
when needed, but then the code continues as if nothing had happened.

rc_read() is a void function and it's on the top of performance critical
call stacks, so propagating the error code via return values doesn't sound
like the best fix.  It seems better to check rc->buffer_size (which holds
the return value of rc->fill()) in the main loop.  It does nothing bad
that the code runs a little with unknown data after a failed rc->fill().

This fixes an infinite loop in initramfs decompression if the
LZMA-compressed initramfs image is corrupt.

Signed-off-by: Lasse Collin <lasse.collin@tukaani.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Alain Knaff <alain@knaff.lu>
Cc: Albin Tonnerre <albin.tonnerre@free-electrons.com>
Cc: Phillip Lougher <phillip@lougher.demon.co.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Larhzu authored and torvalds committed Jan 13, 2011
1 parent 8218a43 commit 278208d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/decompress_unlzma.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,13 +631,16 @@ STATIC inline int INIT unlzma(unsigned char *buf, int in_len,
if (cst.rep0 == 0)
break;
}
if (rc.buffer_size <= 0)
goto exit_3;
}

if (posp)
*posp = rc.ptr-rc.buffer;
if (wr.flush)
wr.flush(wr.buffer, wr.buffer_pos);
ret = 0;
exit_3:
large_free(p);
exit_2:
if (!output)
Expand Down

0 comments on commit 278208d

Please sign in to comment.