Correctly check that compress gone well before using the result buffer.

We need to check the return code of compress.
Compress may fail for different reason, one being that the compr_buffer
is not large enough.
This commit is contained in:
Matthieu Gautier 2017-03-15 09:50:43 +01:00
parent 3592cd84c6
commit e27ce444c6

View File

@ -166,9 +166,9 @@ bool compress_content(string &content,
pthread_mutex_lock(&compressorLock);
compr_buffer.reserve(COMPRESSOR_BUFFER_SIZE);
uLongf comprLen = COMPRESSOR_BUFFER_SIZE;
compress(&compr_buffer[0], &comprLen, (const Bytef*)(content.data()), contentLength);
int err = compress(&compr_buffer[0], &comprLen, (const Bytef*)(content.data()), contentLength);
if (comprLen > 2 && comprLen < (contentLength+2)) {
if (err == Z_OK && comprLen > 2 && comprLen < (contentLength+2)) {
/* /!\ Internet Explorer has a bug with deflate compression.
It can not handle the first two bytes (compression headers)