mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Fixes related to brotli. Errors occured on https://www.thetrendspotter.net/
This commit is contained in:
parent
3e436b8869
commit
b1d1e4a15b
@ -31,6 +31,7 @@ struct br_enc_data {
|
|||||||
size_t avail_in;
|
size_t avail_in;
|
||||||
size_t avail_out;
|
size_t avail_out;
|
||||||
size_t total_out;
|
size_t total_out;
|
||||||
|
unsigned char *buffer;
|
||||||
|
|
||||||
/* The file descriptor from which we read. */
|
/* The file descriptor from which we read. */
|
||||||
int fdread;
|
int fdread;
|
||||||
@ -115,7 +116,6 @@ brotli_decode_buffer(struct stream_encoded *st, unsigned char *data, int len, in
|
|||||||
{
|
{
|
||||||
struct br_enc_data *enc_data = (struct br_enc_data *)st->data;
|
struct br_enc_data *enc_data = (struct br_enc_data *)st->data;
|
||||||
BrotliDecoderState *state = enc_data->state;
|
BrotliDecoderState *state = enc_data->state;
|
||||||
unsigned char *buffer = NULL;
|
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
*new_len = 0; /* default, left there if an error occurs */
|
*new_len = 0; /* default, left there if an error occurs */
|
||||||
@ -124,21 +124,19 @@ brotli_decode_buffer(struct stream_encoded *st, unsigned char *data, int len, in
|
|||||||
|
|
||||||
enc_data->next_in = data;
|
enc_data->next_in = data;
|
||||||
enc_data->avail_in = len;
|
enc_data->avail_in = len;
|
||||||
enc_data->total_out = 0;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
unsigned char *new_buffer;
|
unsigned char *new_buffer;
|
||||||
size_t size = enc_data->total_out + ELINKS_BROTLI_BUFFER_LENGTH;
|
size_t size = enc_data->total_out + ELINKS_BROTLI_BUFFER_LENGTH;
|
||||||
|
new_buffer = mem_realloc(enc_data->buffer, size);
|
||||||
new_buffer = mem_realloc(buffer, size);
|
|
||||||
|
|
||||||
if (!new_buffer) {
|
if (!new_buffer) {
|
||||||
error = BROTLI_DECODER_RESULT_ERROR;
|
error = BROTLI_DECODER_RESULT_ERROR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer = new_buffer;
|
enc_data->buffer = new_buffer;
|
||||||
enc_data->next_out = buffer + enc_data->total_out;
|
enc_data->next_out = enc_data->buffer + enc_data->total_out;
|
||||||
enc_data->avail_out = ELINKS_BROTLI_BUFFER_LENGTH;
|
enc_data->avail_out = ELINKS_BROTLI_BUFFER_LENGTH;
|
||||||
|
|
||||||
error = BrotliDecoderDecompressStream(state, &enc_data->avail_in, &enc_data->next_in,
|
error = BrotliDecoderDecompressStream(state, &enc_data->avail_in, &enc_data->next_in,
|
||||||
@ -147,12 +145,15 @@ brotli_decode_buffer(struct stream_encoded *st, unsigned char *data, int len, in
|
|||||||
if (error == BROTLI_DECODER_RESULT_SUCCESS) {
|
if (error == BROTLI_DECODER_RESULT_SUCCESS) {
|
||||||
*new_len = enc_data->total_out;
|
*new_len = enc_data->total_out;
|
||||||
enc_data->after_end = 1;
|
enc_data->after_end = 1;
|
||||||
return buffer;
|
return enc_data->buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (error == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT);
|
} while (error == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT);
|
||||||
|
|
||||||
mem_free_if(buffer);
|
if (error == BROTLI_DECODER_RESULT_ERROR) {
|
||||||
|
mem_free_if(enc_data->buffer);
|
||||||
|
enc_data->buffer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user