Skip to content

Commit 1da914e

Browse files
Larhzutorvalds
authored andcommitted
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 <[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]>
1 parent 3031480 commit 1da914e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

lib/decompress_inflate.c

+13-4
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,22 @@ STATIC int INIT gunzip(unsigned char *buf, int len,
9898
* possible asciz filename)
9999
*/
100100
strm->next_in = zbuf + 10;
101+
strm->avail_in = len - 10;
101102
/* skip over asciz filename */
102103
if (zbuf[3] & 0x8) {
103-
while (strm->next_in[0])
104-
strm->next_in++;
105-
strm->next_in++;
104+
do {
105+
/*
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++);
106116
}
107-
strm->avail_in = len - (strm->next_in - zbuf);
108117

109118
strm->next_out = out_buf;
110119
strm->avail_out = out_len;

0 commit comments

Comments
 (0)