Skip to content

Commit

Permalink
decompressors: check input size in decompress_inflate.c
Browse files Browse the repository at this point in the history
Check for end of the input buffer when skipping over the filename field in
the .gz file header.

Signed-off-by: Lasse Collin <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Cc: Alain Knaff <[email protected]>
Cc: Albin Tonnerre <[email protected]>
Cc: Phillip Lougher <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Larhzu authored and torvalds committed Jan 13, 2011
1 parent 3031480 commit 1da914e
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/decompress_inflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,22 @@ STATIC int INIT gunzip(unsigned char *buf, int len,
* possible asciz filename)
*/
strm->next_in = zbuf + 10;
strm->avail_in = len - 10;
/* skip over asciz filename */
if (zbuf[3] & 0x8) {
while (strm->next_in[0])
strm->next_in++;
strm->next_in++;
do {
/*
* If the filename doesn't fit into the buffer,
* the file is very probably corrupt. Don't try
* to read more data.
*/
if (strm->avail_in == 0) {
error("header error");
goto gunzip_5;
}
--strm->avail_in;
} while (*strm->next_in++);
}
strm->avail_in = len - (strm->next_in - zbuf);

strm->next_out = out_buf;
strm->avail_out = out_len;
Expand Down

0 comments on commit 1da914e

Please sign in to comment.