php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69706 getimagesize() can fail if the underlying stream doensn't support seeking
Submitted: 2015-05-25 18:29 UTC Modified: 2024-07-21 22:16 UTC
Votes:12
Avg. Score:4.2 ± 0.9
Reproduced:10 of 10 (100.0%)
Same Version:4 (40.0%)
Same OS:3 (30.0%)
From: deviantintegral at gmail dot com Assigned: cmb (profile)
Status: No Feedback Package: GetImageSize related
PHP Version: 5.6.9 OS: Any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: deviantintegral at gmail dot com
New email:
PHP Version: OS:

 

 [2015-05-25 18:29 UTC] deviantintegral at gmail dot com
Description:
------------
I've verified this is an issue on PHP 5.4, 5.6, and statically on the master branch.

The AWS SDK (https://aws.amazon.com/sdk-for-php/) includes a stream wrapper that by default does not support seeking on files backed by S3. Calling getimagesize() on an image can fail if php_skip_variable() is called. I've seen this happen with images that specify the "Image Quality" EXIF tag, which is the M_APP15 constant in ext/standard/image.c.

The stream documentation states that seeking is not required to be supported by stream wrappers, and it's not clear that getimagesize() needs seeking to work properly.

I see two ways to improve this:

* Log a notice if php_skip_variable() tries to seek on an unseekable stream. That would have saved me a ton of time tracing this with GDB.
* Or, if a stream is not seekable, copy the file to the temporary file system and fetch metadata from there. 


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-04-02 11:25 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2020-04-02 11:25 UTC] cmb@php.net
For SEEK_CUR and positive offsets, non-seekable streams are
supposed to be read (discarding what was written).  So if you can
still reproduce this issue with any of the actively supported PHP
versions[1], please provide a minimal self-contained reproduce
script.

[1] <https://www.php.net/supported-versions.php>
 [2020-04-12 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2024-04-17 11:14 UTC] jyri-petteri dot paloposki at ardcoras dot fi
I think I bumped into this exact problem. I implemented a simple custom stream wrapper in Drupal 10 that uses Guzzle client to stream an external resource to create an image style version of it. Before implementing seeking in the stream wrapper, getimagesize() returned FALSE to some valid images after only reading a few chunks from the stream. This happened for example with flamma.helsinki.fi/documents/20142/1540081/upload_00095252.jpg . When I added seeking, getimagesize detected the image correctly and everything worked.
 [2024-07-21 22:16 UTC] cmb@php.net
This may have been fixed in the meantime; if not, please file a new ticket at <https://github.com/php/php-src/issues>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 19:01:27 2024 UTC