diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2011-01-12 20:01:25 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-01-13 11:03:25 -0500 |
commit | 1da914e0648ace34e1c3738d9584e8b2cd6fe64a (patch) | |
tree | d52798bed2086ea7fd9182ff1e9ddae8b09c4740 /lib | |
parent | 303148045aac34b70db722a54e5ad94a3a6625c6 (diff) |
decompressors: check input size in decompress_inflate.c
Check for end of the input buffer when skipping over the filename field in
the .gz file header.
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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/decompress_inflate.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/lib/decompress_inflate.c b/lib/decompress_inflate.c index b5fe1d1d5f0..19ff89e34ee 100644 --- a/lib/decompress_inflate.c +++ b/lib/decompress_inflate.c | |||
@@ -98,13 +98,22 @@ STATIC int INIT gunzip(unsigned char *buf, int len, | |||
98 | * possible asciz filename) | 98 | * possible asciz filename) |
99 | */ | 99 | */ |
100 | strm->next_in = zbuf + 10; | 100 | strm->next_in = zbuf + 10; |
101 | strm->avail_in = len - 10; | ||
101 | /* skip over asciz filename */ | 102 | /* skip over asciz filename */ |
102 | if (zbuf[3] & 0x8) { | 103 | if (zbuf[3] & 0x8) { |
103 | while (strm->next_in[0]) | 104 | do { |
104 | strm->next_in++; | 105 | /* |
105 | strm->next_in++; | 106 | * If the filename doesn't fit into the buffer, |
107 | * the file is very probably corrupt. Don't try | ||
108 | * to read more data. | ||
109 | */ | ||
110 | if (strm->avail_in == 0) { | ||
111 | error("header error"); | ||
112 | goto gunzip_5; | ||
113 | } | ||
114 | --strm->avail_in; | ||
115 | } while (*strm->next_in++); | ||
106 | } | 116 | } |
107 | strm->avail_in = len - (strm->next_in - zbuf); | ||
108 | 117 | ||
109 | strm->next_out = out_buf; | 118 | strm->next_out = out_buf; |
110 | strm->avail_out = out_len; | 119 | strm->avail_out = out_len; |