Bug #77104 [Com]: exif_read_data will fail with EOF on non-file streams containing large tags

From: Date: Sun, 04 Nov 2018 02:28:25 +0000
Subject: Bug #77104 [Com]: exif_read_data will fail with EOF on non-file streams containing large tags
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-217814@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77104&edit=1 ID: 77104 Comment by: magicaltux at gmail dot com Reported by: magicaltux at gmail dot com Summary: exif_read_data will fail with EOF on non-file streams containing large tags Status: Open Type: Bug Package: EXIF related Operating System: Linux PHP Version: 7.2.11 Block user comment: N Private report: N New Comment: Some notes as I run more tests. My failing file, a Photoshop generated TIFF, has the following large EXIF tags: ExtensibleMetadataPlatform (17178 bytes) ImageResourceInformation (5326 bytes) ImageSourceData (1404340 bytes) Using stream_set_chunk_size() to increase chunk size to a value higher than largest tag size (at 1.5MB) resolves issue but strongly affects performances as all reads are of that size. Using stream_set_chunk_size() to set chunk size to 1 (from main/streams/streams.c in _php_stream_read() there is a check for stream->chunk_size == 1) then the read passed to the stream wrapper are no longer of a fixed chunk size but as requested by the caller. This resolves this issue without impacting performances too much. Previous Comments: ------------------------------------------------------------------------ [2018-11-04 02:12:03] magicaltux at gmail dot com Description: ------------ exif_read_data() accepts a mixed $stream parameter to read from, however the source code makes use of php_stream_read() and will return a "Unexpected end of file reached" error if not enough bytes are returned. However php_stream_read() when used on something else than a regular file (a seekable stream wrapper in my case) only perform a single call for 8192 bytes maximum, leaving ext/exif return a EOF error. Two places in the code: https://github.com/php/php-src/blob/master/ext/exif/exif.c#L3300 https://github.com/php/php-src/blob/master/ext/exif/exif.c#L3793 ext/exif should, in case php_stream_read() was able to read some but not all bytes, continue reading until nothing is read at all or requested data is read. Test script: --------------- (writing a specific test for this would require a lot of work as it'd need a stream wrapper/etc) Actual result: -------------- Warning: exif_read_data(): Unexpected end of file reached in test.php on line 9 Warning: exif_read_data(): Invalid TIFF file in test.php on line 9 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77104&edit=1

« previous php.bugs (#217814) next »