php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19315 getimagesize results wrong sizes
Submitted: 2002-09-09 08:11 UTC Modified: 2002-09-18 15:42 UTC
From: alberty at neptunelabs dot de Assigned: derick (profile)
Status: Closed Package: GetImageSize related
PHP Version: 4CVS-2002-09-09 OS: i686-pc-linux-gnu
Private report: No CVE-ID: None
 [2002-09-09 08:11 UTC] alberty at neptunelabs dot de
Hi,

the new feature of getimagesize to results the size of compressed swf
files results in the most cases wrong results, because the current
function try to get only a part of the compressed file.

You can validate the problem with files in macromedias trial
version of flash, found in 
X:\Program Files\Macromedia\Flash MX\Samples\SWF
(eg:360_degrees.swf,Clock.swf,Drawing.swf,Import_video.swf)

Regards,

Steve

here a possible working patch:
------------------------------
205,214c205,213
< static struct gfxinfo *php_handle_swc(php_stream * stream TSRMLS_DC)
< {
< 	struct gfxinfo *result = NULL;
< 
< 	long bits;
< 	unsigned char a[64];
< 	unsigned long len = 64;
< 	char *b;
< 
< 	b = ecalloc (1, len + 1);
---
> static struct gfxinfo *php_handle_swc(php_stream * stream TSRMLS_DC)
> {
> 	struct gfxinfo *result = NULL;
> 	
> 	long bits;
> 	unsigned long length;
> 	char *b;
> 	char *ccontents;
> 	int clen;
216,217c215,232
< 	result = (struct gfxinfo *) ecalloc (1, sizeof (struct gfxinfo));
< 	php_stream_seek(stream, 5, SEEK_CUR);
---
>   result = (struct gfxinfo *) ecalloc (1, sizeof (struct gfxinfo));
> 	
> 	php_stream_seek(stream, 5, SEEK_CUR);
> 	
> 	if ((clen = php_stream_copy_to_mem(stream, &ccontents, PHP_STREAM_COPY_ALL, 0)) > 0)
> 	{
> 		length=clen*2;
> 		b= ecalloc (1, length + 1);
> 		uncompress (b, &length, ccontents, clen);
> 	
> 	  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;
> 	  efree (b);
> 	
> 	}
219,220c234,236
< 	php_stream_read(stream, a, sizeof(a)); /* fread(a, sizeof(a), 1, fp); */
< 	uncompress (b, &len, a, sizeof(a));
---
>   result->bits     = 0;
>   result->channels = 0;
>   return result;
222,230d237
< 	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;
< 	efree (b);
< 	result->bits     = 0;
< 	result->channels = 0;
< 	return result;

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-09-09 08:16 UTC] derick@php.net
Can you post an unified diff (diff -u)?

Derick
 [2002-09-09 11:33 UTC] alberty at neptunelabs dot de
--- php4/ext/standard/image.c	Mon Sep  9 14:19:09 2002
+++ image.c	Mon Sep  9 14:43:17 2002
@@ -202,32 +202,39 @@
 #if HAVE_ZLIB
 /* {{{ php_handle_swc
  */
-static struct gfxinfo *php_handle_swc(php_stream * stream TSRMLS_DC)
-{
-	struct gfxinfo *result = NULL;
-
-	long bits;
-	unsigned char a[64];
-	unsigned long len = 64;
-	char *b;
-
-	b = ecalloc (1, len + 1);
+static struct gfxinfo *php_handle_swc(php_stream * stream TSRMLS_DC)
+{
+	struct gfxinfo *result = NULL;
+	
+	long bits;
+	unsigned long length;
+	char *b;
+	char *ccontents;
+	int clen;
 
-	result = (struct gfxinfo *) ecalloc (1, sizeof (struct gfxinfo));
-	php_stream_seek(stream, 5, SEEK_CUR);
+  result = (struct gfxinfo *) ecalloc (1, sizeof (struct gfxinfo));
+	
+	php_stream_seek(stream, 5, SEEK_CUR);
+	
+	if ((clen = php_stream_copy_to_mem(stream, &ccontents, PHP_STREAM_COPY_ALL, 0)) > 0)
+	{
+		length=clen*2;
+		b= ecalloc (1, length + 1);
+		uncompress (b, &length, ccontents, clen);
+	
+	  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;
+	  efree (b);
+	
+	}
 
-	php_stream_read(stream, a, sizeof(a)); /* fread(a, sizeof(a), 1, fp); */
-	uncompress (b, &len, a, sizeof(a));
+  result->bits     = 0;
+  result->channels = 0;
+  return result;
 	
-	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;
-	efree (b);
-	result->bits     = 0;
-	result->channels = 0;
-	return result;
 }
 /* }}} */
 #endif
 [2002-09-18 15:42 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 09 04:01:27 2024 UTC