From e27ce444c61c4159dc2e8e7790b2f641c5cf0967 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 15 Mar 2017 09:50:43 +0100 Subject: [PATCH] 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. --- src/server/kiwix-serve.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/server/kiwix-serve.cpp b/src/server/kiwix-serve.cpp index e2fa03f..c5ae5c4 100644 --- a/src/server/kiwix-serve.cpp +++ b/src/server/kiwix-serve.cpp @@ -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)