From 869c42a511f5a89d7afaf5e0ef5b66128da9170f Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Wed, 18 Sep 2002 20:37:24 +0000 Subject: [PATCH] Added additional handlers for compressed swf files, which require entire file to be downloaded for successful decompression. --- ext/standard/image.c | 57 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/ext/standard/image.c b/ext/standard/image.c index 6b9f8bc647..722e2a2247 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -208,8 +208,10 @@ static struct gfxinfo *php_handle_swc(php_stream * stream TSRMLS_DC) long bits; unsigned char a[64]; - unsigned long len = 64; - char *b; + unsigned long len=64, szlength; + int factor=1,maxfactor=16; + int slength, status=0; + char *b, *buf=NULL, *bufz=NULL; b = ecalloc (1, len + 1); @@ -217,13 +219,52 @@ static struct gfxinfo *php_handle_swc(php_stream * stream TSRMLS_DC) php_stream_seek(stream, 5, SEEK_CUR); php_stream_read(stream, a, sizeof(a)); /* fread(a, sizeof(a), 1, fp); */ - uncompress (b, &len, a, sizeof(a)); + if (uncompress(b, &len, a, sizeof(a)) != Z_OK) { + /* failed to decompress the file, will try reading the rest of the file */ + php_stream_seek(stream, 8, SEEK_SET); + slength = php_stream_copy_to_mem(stream, &bufz, PHP_STREAM_COPY_ALL, 0); + + /* + * zlib::uncompress() wants to know the output data length + * if none was given as a parameter + * we try from input length * 2 up to input length * 2^8 + * doubling it whenever it wasn't big enough + * that should be eneugh for all real life cases + */ + + do { + szlength=slength*(1<width = (php_swf_get_bits (b, 5 + bits, bits) - - php_swf_get_bits (b, 5, bits)) / 20; - result->height = (php_swf_get_bits (b, 5 + (3 * bits), bits) - - php_swf_get_bits (b, 5 + (2 * bits), bits)) / 20; + if (!status) { + bits = php_swf_get_bits (b, 0, 5); + result->width = (php_swf_get_bits (b, 5 + bits, bits) - + php_swf_get_bits (b, 5, bits)) / 20; + result->height = (php_swf_get_bits (b, 5 + (3 * bits), bits) - + php_swf_get_bits (b, 5 + (2 * bits), bits)) / 20; + } else { + result->width = result->height = 0; + } + efree (b); result->bits = 0; result->channels = 0; -- 2.50.1