Bug #75708 [Ver]: getimagesize with "&$imageinfo" fails on StreamWrappers

From: Date: Sun, 15 Oct 2023 16:02:16 +0000
Subject: Bug #75708 [Ver]: getimagesize with "&$imageinfo" fails on StreamWrappers
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-245581@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75708&edit=1

 ID:                 75708
 Updated by:         bukka@php.net
 Reported by:        joehoyle at gmail dot com
 Summary:            getimagesize with "&$imageinfo" fails on
                     StreamWrappers
 Status:             Verified
 Type:               Bug
 Package:            Streams related
 Operating System:   Alpine Linux
 PHP Version:        7.1.12
 Assigned To:        bukka
 Block user comment: N
 Private report:     N

 New Comment:

The PR is attached. Most work was really to debug the whole thing which is quite usual for stream
related things.


Previous Comments:
------------------------------------------------------------------------
[2023-10-15 16:01:13] bukka@php.net

The pattern is that it needs to be image with large APPn data (larger than one stream chunk). I
managed to create easily that file with GIMP by creating small image and editing its metadata to
contain very large description text (just added long lorem ipsum).

------------------------------------------------------------------------
[2023-10-15 15:58:18] bukka@php.net

The following pull request has been associated:

Patch Name: Fix bug #75708: getimagesize with "&$imageinfo" fails on StreamWrappers
On GitHub:  https://github.com/php/php-src/pull/12444
Patch:      https://github.com/php/php-src/pull/12444.patch

------------------------------------------------------------------------
[2023-09-23 20:41:49] bukka@php.net

I have spent quite a bit of time on this today and the reason is that stream wrapper does not use
greedy reading so not the whole length is returned if the chunk is read full. This happens only for
some images so I will need to figure the pattern out as I'm able to recreate only for really
big images which is not convenient for test addition. Otherwise I have got a fix in https://github.com/bukka/php-src/commit/88a8095a20c6598cdf6e3ce0b2a6849fb58c5a8b
but need to finish the test as I said.

The whole stream handling seems a bit incomplete as even with var it does not check seek return
value which is not probably right. The whole handling needs more looking and investigation and some
follow up fixes are likely.

------------------------------------------------------------------------
[2018-06-22 14:23:28] requinix@php.net

Related To: Bug #76521

------------------------------------------------------------------------
[2017-12-20 16:18:55] 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>

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=75708


--
Edit this bug report at https://bugs.php.net/bug.php?id=75708&edit=1


Thread (7 messages)

« previous php.bugs (#245581) next »