mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-26 05:41:18 -04:00
+ fix segfault if compress() return empty string
This commit is contained in:
parent
8121f83d61
commit
4c79cfcf06
@ -17,6 +17,8 @@
|
|||||||
* MA 02110-1301, USA.
|
* MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define KIWIX_MIN_CONTENT_SIZE_TO_DEFLATE 100
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#import <sys/types.h>
|
#import <sys/types.h>
|
||||||
#import <sys/sysctl.h>
|
#import <sys/sysctl.h>
|
||||||
@ -344,23 +346,32 @@ static int accessHandlerCallback(void *cls,
|
|||||||
/* Compute the lengh */
|
/* Compute the lengh */
|
||||||
contentLength = content.size();
|
contentLength = content.size();
|
||||||
|
|
||||||
|
/* Should be deflate */
|
||||||
|
bool deflated =
|
||||||
|
contentLength > KIWIX_MIN_CONTENT_SIZE_TO_DEFLATE &&
|
||||||
|
acceptEncodingDeflate &&
|
||||||
|
mimeType.find("text/") != string::npos;
|
||||||
|
|
||||||
/* Compress the content if necessary */
|
/* Compress the content if necessary */
|
||||||
if (acceptEncodingDeflate && mimeType.find("text/") != string::npos) {
|
if (deflated) {
|
||||||
pthread_mutex_lock(&compressorLock);
|
pthread_mutex_lock(&compressorLock);
|
||||||
comprLen = COMPRESSOR_BUFFER_SIZE;
|
comprLen = COMPRESSOR_BUFFER_SIZE;
|
||||||
|
|
||||||
compress(compr, &comprLen, (const Bytef*)(content.data()), contentLength);
|
compress(compr, &comprLen, (const Bytef*)(content.data()), contentLength);
|
||||||
|
|
||||||
/* /!\ Internet Explorer has a bug with deflate compression.
|
if (comprLen > 2 && comprLen < contentLength) {
|
||||||
It can not handle the first two bytes (compression headers)
|
|
||||||
We need to chunk them off (move the content 2bytes)
|
|
||||||
It has no incidence on other browsers
|
|
||||||
See http://www.subbu.org/blog/2008/03/ie7-deflate-or-not and comments */
|
|
||||||
compr++;
|
|
||||||
compr++;
|
|
||||||
|
|
||||||
content = string((char *)compr, comprLen);
|
/* /!\ Internet Explorer has a bug with deflate compression.
|
||||||
contentLength = comprLen;
|
It can not handle the first two bytes (compression headers)
|
||||||
|
We need to chunk them off (move the content 2bytes)
|
||||||
|
It has no incidence on other browsers
|
||||||
|
See http://www.subbu.org/blog/2008/03/ie7-deflate-or-not and comments */
|
||||||
|
compr += 2;
|
||||||
|
|
||||||
|
content = string((char *)compr, comprLen);
|
||||||
|
contentLength = comprLen;
|
||||||
|
} else {
|
||||||
|
deflated = false;
|
||||||
|
}
|
||||||
|
|
||||||
pthread_mutex_unlock(&compressorLock);
|
pthread_mutex_unlock(&compressorLock);
|
||||||
}
|
}
|
||||||
@ -377,10 +388,10 @@ static int accessHandlerCallback(void *cls,
|
|||||||
httpResponseCode = MHD_HTTP_FOUND;
|
httpResponseCode = MHD_HTTP_FOUND;
|
||||||
} else {
|
} else {
|
||||||
/* Add if necessary the content-encoding */
|
/* Add if necessary the content-encoding */
|
||||||
if (acceptEncodingDeflate && mimeType.find("text/") != string::npos) {
|
if (deflated) {
|
||||||
MHD_add_response_header(response, "Content-encoding", "deflate");
|
MHD_add_response_header(response, "Content-encoding", "deflate");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Specify the mime type */
|
/* Specify the mime type */
|
||||||
MHD_add_response_header(response, "Content-Type", mimeType.c_str());
|
MHD_add_response_header(response, "Content-Type", mimeType.c_str());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user