php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75708 getimagesize with "&$imageinfo" fails on StreamWrappers
Submitted: 2017-12-20 02:54 UTC Modified: 2017-12-20 16:18 UTC
From: joehoyle at gmail dot com Assigned:
Status: Verified Package: Streams related
PHP Version: 7.1.12 OS: Alpine Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: joehoyle at gmail dot com
New email:
PHP Version: OS:

 

 [2017-12-20 02:54 UTC] joehoyle at gmail dot com
Description:
------------
When using getimagesize( $path, $imageinfo ) on specific images in conjunction with a custom StreamWrapper path, multiple "PHP Warning:  getimagesize(): corrupt JPEG data: 536 extraneous bytes before marker in..." errors are shown, and the $imageinfo is empty.

This also happens with a "fake filesystem streamwrapper" as demonstrated.

Test script:
---------------
https://gist.github.com/joehoyle/b9484e6375ce3a1d4cbefe5e439ef80d

Using image: https://joehoyle-captured.s3.amazonaws.com/test.jpg

Expected result:
----------------
bool(true)
bool(true)
[20-Dec-2017 02:51:20 UTC] PHP Warning:  getimagesize(): corrupt JPEG data: 183 extraneous bytes before marker in /usr/src/app/test.php on line 60
[20-Dec-2017 02:51:20 UTC] PHP Warning:  getimagesize(): corrupt JPEG data: 140 extraneous bytes before marker in /usr/src/app/test.php on line 60
[20-Dec-2017 02:51:20 UTC] PHP Warning:  getimagesize(): corrupt JPEG data: 175 extraneous bytes before marker in /usr/src/app/test.php on line 60
[20-Dec-2017 02:51:20 UTC] PHP Warning:  getimagesize(): corrupt JPEG data: 854 extraneous bytes before marker in /usr/src/app/test.php on line 60
[20-Dec-2017 02:51:20 UTC] PHP Warning:  getimagesize(): corrupt JPEG data: 723 extraneous bytes before marker in /usr/src/app/test.php on line 60
[20-Dec-2017 02:51:20 UTC] PHP Warning:  getimagesize(): corrupt JPEG data: 31 extraneous bytes before marker in /usr/src/app/test.php on line 60
[20-Dec-2017 02:51:20 UTC] PHP Warning:  getimagesize(): corrupt JPEG data: 79 extraneous bytes before marker in /usr/src/app/test.php on line 60
[20-Dec-2017 02:51:20 UTC] PHP Warning:  getimagesize(): corrupt JPEG data: 502 extraneous bytes before marker in /usr/src/app/test.php on line 60
[20-Dec-2017 02:51:20 UTC] PHP Warning:  getimagesize(): corrupt JPEG data: 48 extraneous bytes before marker in /usr/src/app/test.php on line 60
[20-Dec-2017 02:51:20 UTC] PHP Warning:  getimagesize(): corrupt JPEG data: 116 extraneous bytes before marker in /usr/src/app/test.php on line 60
[20-Dec-2017 02:51:20 UTC] PHP Warning:  getimagesize(): corrupt JPEG data: 295 extraneous bytes before marker in /usr/src/app/test.php on line 60
[20-Dec-2017 02:51:20 UTC] PHP Warning:  getimagesize(): corrupt JPEG data: 710 extraneous bytes before marker in /usr/src/app/test.php on line 60
[20-Dec-2017 02:51:20 UTC] PHP Warning:  getimagesize(): corrupt JPEG data: 536 extraneous bytes before marker in /usr/src/app/test.php on line 60
done

Actual result:
--------------
bool(true)
bool(true)
done

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-12-20 16:18 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2017-12-20 16:18 UTC] cmb@php.net
I can confirm the erroneous behavior.  Interestingly, calling
getimagesize() without the second parameter succeeds without
warnings.  The only relevant difference is that the info parameter
causes php_read_APP() to be called, while without info parameter
php_skip_variable() is called[1].  However, the relevant
difference between php_skip_variable()[2] and php_read_APP()[3] is
that the former calls php_stream_seek() while the latter calls
php_stream_read() (both with the same offset/length).  Apparently,
there is an issue regarding php_stream_read(); possibly related to
bug #72561.

[1] <https://github.com/php/php-src/blob/PHP-7.2.0/ext/standard/image.c#L535-L543>
[2] <https://github.com/php/php-src/blob/PHP-7.2.0/ext/standard/image.c#L424-L437>
[3] <https://github.com/php/php-src/blob/PHP-7.2.0/ext/standard/image.c#L439-L471>
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Tue Oct 16 13:01:25 2018 UTC