Z.avail_out = *encoded_len;
status = deflate(&Z, Z_FINISH);
+ deflateEnd(&Z);
+
if (Z_STREAM_END == status) {
/* size buffer down to actual length */
*encoded = erealloc(*encoded, Z.total_out + 1);
(*encoded)[*encoded_len = Z.total_out] = '\0';
- deflateEnd(&Z);
return SUCCESS;
} else {
STR_SET(*encoded, NULL);
}
}
- http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not deflate data: %s (%s)", zError(status), Z.msg);
- deflateEnd(&Z);
+ http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not deflate data: %s (%s)", zError(status));
return FAILURE;
}
Z.avail_in = data_len;
do {
- phpstr_resize(&buffer, data_len);
+ phpstr_resize(&buffer, data_len << 2);
do {
- Z.next_out = buffer.data + (buffer.used += Z.total_out);
- Z.avail_out = (buffer.free -= Z.total_out);
+ Z.avail_out = (buffer.free -= Z.total_out - buffer.used);
+ Z.next_out = buffer.data + (buffer.used = Z.total_out);
status = inflate(&Z, Z_NO_FLUSH);
} while (Z_OK == status);
-
} while (Z_BUF_ERROR == status && ++max < HTTP_ENCODING_MAXTRY);
if (Z_DATA_ERROR == status && HTTP_WINDOW_BITS_ANY == wbits) {
goto retry_inflate;
}
+ inflateEnd(&Z);
+
if (Z_STREAM_END == status) {
- *decoded = erealloc(buffer.data, (buffer.used += Z.total_out) + 1);
- (*decoded)[*decoded_len = buffer.used] = '\0';
- inflateEnd(&Z);
+ *decoded_len = Z.total_out;
+ *decoded = erealloc(buffer.data, *decoded_len + 1);
+ (*decoded)[*decoded_len] = '\0';
return SUCCESS;
} else {
phpstr_dtor(&buffer);
}
}
- http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not inflate data: %s (%s)", zError(status), Z.msg);
- inflateEnd(&Z);
+ http_error_ex(HE_WARNING, HTTP_E_ENCODING, "Could not inflate data: %s", zError(status));
return FAILURE;
}
extern PHP_MINIT_FUNCTION(http_encoding);
-/* max count of uncompress trials, alloc_size <<= 2 for each try */
-#define HTTP_ENCODING_MAXTRY 10
+#define HTTP_ENCODING_MAXTRY 100
/* safe padding */
#define HTTP_ENCODING_SAFPAD 28
/* add 1% extra space in case we need to encode widely differing (binary) data */