iliaa Wed Sep 18 16:37:24 2002 EDT
Modified files:
/php4/ext/standard image.c
Log:
Added additional handlers for compressed swf files, which require
entire file to be downloaded for successful decompression.
Index: php4/ext/standard/image.c
diff -u php4/ext/standard/image.c:1.68 php4/ext/standard/image.c:1.69
--- php4/ext/standard/image.c:1.68 Fri Sep 6 02:39:57 2002
+++ php4/ext/standard/image.c Wed Sep 18 16:37:24 2002
@@ -16,7 +16,7 @@
| Marcus Boerger <[EMAIL PROTECTED]> |
+----------------------------------------------------------------------+
*/
-/* $Id: image.c,v 1.68 2002/09/06 06:39:57 hyanantha Exp $ */
+/* $Id: image.c,v 1.69 2002/09/18 20:37:24 iliaa Exp $ */
/*
* Based on Daniel Schmitt's imageinfo.c which carried the following
* Copyright notice.
@@ -208,8 +208,10 @@
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 @@
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<<factor++);
+ buf = (char *) erealloc(buf,szlength);
+ if (!buf) {
+ status = 1;
+ break;
+ }
+ status = uncompress(buf, &szlength, bufz, slength);
+ } while ((status==Z_BUF_ERROR)&&(factor<maxfactor));
+
+ if (bufz) {
+ pefree(bufz, 0);
+ }
+
+ if (status == Z_OK) {
+ memcpy(b, buf, len);
+ }
+
+ if (buf) {
+ efree(buf);
+ }
+ }
- 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;
+ 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;
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php