1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-27 02:56:18 -04:00

bug 1083: Fix infinite loop in decompress_data

decompress_data() supposed that read_encoded() would return a positive
number if it decompressed something, 0 if no data is available yet but
may be later, or -1 if no more data will be available.  However,
several backends actually returned 0 if they had seen an EOF marker or
an error in the stream, causing decompress_data() to keep calling
them.  Make them return -1 in this situation.
This commit is contained in:
Kalle Olavi Niemitalo 2009-08-15 13:44:03 +03:00 committed by Kalle Olavi Niemitalo
parent 4369b052ef
commit cd2eeef5f7
5 changed files with 24 additions and 7 deletions

2
NEWS
View File

@ -18,6 +18,8 @@ Bugs that should be removed from NEWS before the 0.12.0 release:
ELinks could crash; as a precaution, don't allow other actions
either. ELinks 0.12pre1 was the first release that supported
``elinks.action''.
* critical bug 1083: Avoid an infinite loop when trying to decompress
malformed data. Caused by the bug 1068 fix in ELinks 0.12pre3.
ELinks 0.12pre5:
----------------

View File

@ -88,7 +88,7 @@ bzip2_read(struct stream_encoded *stream, unsigned char *buf, int len)
assert(len > 0);
if (data->last_read) return 0;
if (data->last_read) return -1;
data->fbz_stream.avail_out = len;
data->fbz_stream.next_out = buf;

View File

@ -99,7 +99,7 @@ deflate_read(struct stream_encoded *stream, unsigned char *buf, int len)
assert(len > 0);
if (data->last_read) return 0;
if (data->last_read) return -1;
data->deflate_stream.avail_out = len;
data->deflate_stream.next_out = buf;

View File

@ -48,7 +48,15 @@ dummy_open(struct stream_encoded *stream, int fd)
static int
dummy_read(struct stream_encoded *stream, unsigned char *data, int len)
{
return safe_read(((struct dummy_enc_data *) stream->data)->fd, data, len);
struct dummy_enc_data *const enc = stream->data;
int got = safe_read(enc->fd, data, len);
if (got > 0)
return got;
else if (got == -1 && errno == EAGAIN)
return 0;
else
return -1;
}
static unsigned char *
@ -118,9 +126,16 @@ open_encoded(int fd, enum stream_encoding encoding)
return NULL;
}
/* Read available data from stream and decode them. Note that when data change
* their size during decoding, 'len' indicates desired size of _returned_ data,
* not desired size of data read from stream. */
/** Read available data from stream and decode them. Note that when
* data change their size during decoding, @a len indicates desired
* size of _returned_ data, not desired size of data read from
* stream.
*
* @return the number of bytes written to the @a data array if
* something was decoded; 0 if no data is available yet but some may
* become available later; or -1 if there will be no further data,
* either because an error occurred or because an end-of-stream mark
* was reached. */
int
read_encoded(struct stream_encoded *stream, unsigned char *data, int len)
{

View File

@ -65,7 +65,7 @@ lzma_read(struct stream_encoded *stream, unsigned char *buf, int len)
assert(len > 0);
if (data->last_read) return 0;
if (data->last_read) return -1;
data->flzma_stream.avail_out = len;
data->flzma_stream.next_out = buf;