php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41321 getimagesize() gives warning on files containing less than 12characters of dat
Submitted: 2007-05-07 20:56 UTC Modified: 2007-06-17 10:39 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: marduc at start dot no Assigned: pajoye (profile)
Status: Closed Package: GetImageSize related
PHP Version: 6.0.0 OS: OS X
Private report: No CVE-ID: None
 [2007-05-07 20:56 UTC] marduc at start dot no
Description:
------------
Checking the mime-types of files using getimagesize() produces a warning (Warning: getimagesize() [function.getimagesize]: Read error!) if the file contains less than 12 characters. That is, a file of any extension containing the sequence abcdefghijk gives a warning. Trying to read a file containing the sequence abcdefghijkl gives no warning. This is done on PHP5.2.1.

Also tested this on PHP5.1.6, and it seems less than 11 characters gives a warning. 

Is php trying to read more bytes than available?

Reproduce code:
---------------
<?
/* the directory asdf/ is a directory which apache is the owner of */
exec("touch asdf/asdf");
fwrite(fopen("asdf/asdf", "w"), "abcdefghijk");
$im = getimagesize("asdf/asdf");
?>

Expected result:
----------------
no output, no warning

Actual result:
--------------
Warning: getimagesize() [function.getimagesize]: Read error! in /Users/torgeir/Sites/test.php on line 4

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-07 21:03 UTC] tony2001@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip


 [2007-05-07 21:04 UTC] marduc at start dot no
Correction to prevois post:
Reading the documentation I noticed "If accessing the filename image is impossible, or if it isn't a valid picture, getimagesize() will generate an error of level E_WARNING", meaning the expected result should be an error of level E_WARNING in any case of the file not being an image.
 [2007-05-07 21:16 UTC] tony2001@php.net
No bug -> bogus.
 [2007-05-07 21:24 UTC] marduc at start dot no
Same thing happens using the latest CVS Snapshot. "Read error!" on getimagesize() on a textfile containing less than 12 characters. No warning on getimagesize() on the same file containing 13 characters.
 [2007-05-07 21:33 UTC] derick@php.net
Why did you reopen? You get a warning, just like the docs say...
 [2007-05-07 21:46 UTC] marduc at start dot no
Am I missing something? The docs says "If accessing the filename image is impossible, or if it isn't a valid picture, getimagesize() will generate an error of level E_WARNING". Using getimagesize on a textfile  containing 12 or more characters or any other file not being a valid picture, say a pdf-document, does not produce a warning? The only time I get a warning is using a textfile containing less than 12 characters.
 [2007-05-08 15:02 UTC] marduc at start dot no
code
----

file_put_contents("test", "123456789012");
echo "12 chars:\n";
var_dump(getimagesize("test"));
file_put_contents("test", "1234567890");
echo "10 chars:\n";
var_dump(getimagesize("test"));


output
------

12 chars:
bool(false)
10 chars:
Warning: getimagesize(): Read error! in /home/user/test.php on line 8
bool(false)
 [2007-05-08 16:24 UTC] with at thesublevels dot com
The same thing happens to me on a linux box with 5.2.2.
The problem is not that an error appears, but that it only appears when you use the function on a very small file. According to the docs the error should appear on all invalid files. 

I do prefer that it doesn't give off any warnings tho as the function is a nice way to check for invalid images. I just use an extra check for the length of the file to avoid the error altogether since no image files get as small as just a couple of bytes.
 [2007-05-08 17:53 UTC] pajoye@php.net
"I do prefer that it doesn't give off any warnings tho as the function is a nice way to check for invalid images."

I agree, such functions should be quiet unless something critical for php happened, invalid images do not fit in this category.
 [2007-05-08 18:38 UTC] iliaa@php.net
This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.

Read errors have been downgraded to E_NOTICE.
 [2007-05-09 09:39 UTC] bjori@php.net
Re-open as documentation problem (see Ilias comment)
 [2007-06-17 10:26 UTC] gwynne@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2007-06-17 10:27 UTC] gwynne@php.net
Re-opening as getimagesize-related as bug was not fixed in HEAD.
 [2007-06-17 10:39 UTC] pajoye@php.net
This bug has been fixed in CVS.

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/.
 
Thank you for the report, and for helping us make PHP better.

Thanks for the head up!
 [2010-11-28 22:23 UTC] markus dot zimmermann at nethead dot at
I am using the following code with PHP 5.3.3
--
<?php

file_put_contents('abc', '12345678901');

$v = getimagesize('abc');

unlink('abc')

?>
--
and I get the notice "getimagesize(): Read error!". Therefore I would say that this is a regression? Do note that with the text '123456789012' I do not get the notice. So it is exactly as the bug opener described it and the bug is not fixed. Please reopen.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 03:01:29 2024 UTC