Skip to content

Commit 997e2e5

Browse files
committed
Ensure that the stream position is kept between reads
1 parent f7d9f64 commit 997e2e5

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

ext/exif/exif.c

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4305,9 +4305,9 @@ static int exif_discard_imageinfo(image_info_type *ImageInfo)
43054305
}
43064306
/* }}} */
43074307

4308-
/* {{{ exif_read_from_stream
4308+
/* {{{ exif_read_from_impl
43094309
*/
4310-
static int exif_read_from_stream(image_info_type *ImageInfo, php_stream *stream, int read_thumbnail, int read_all)
4310+
static int exif_read_from_impl(image_info_type *ImageInfo, php_stream *stream, int read_thumbnail, int read_all)
43114311
{
43124312
int ret;
43134313
zend_stat_t st;
@@ -4368,6 +4368,27 @@ static int exif_read_from_stream(image_info_type *ImageInfo, php_stream *stream,
43684368
}
43694369
/* }}} */
43704370

4371+
/* {{{ exif_read_from_stream
4372+
*/
4373+
static int exif_read_from_stream(image_info_type *ImageInfo, php_stream *stream, int read_thumbnail, int read_all)
4374+
{
4375+
int ret;
4376+
off_t old_pos = php_stream_tell(stream);
4377+
4378+
if (old_pos) {
4379+
php_stream_seek(stream, 0, SEEK_SET);
4380+
}
4381+
4382+
ret = exif_read_from_impl(ImageInfo, stream, read_thumbnail, read_all);
4383+
4384+
if (old_pos) {
4385+
php_stream_seek(stream, old_pos, SEEK_SET);
4386+
}
4387+
4388+
return ret;
4389+
}
4390+
/* }}} */
4391+
43714392
/* {{{ exif_read_from_file
43724393
*/
43734394
static int exif_read_from_file(image_info_type *ImageInfo, char *FileName, int read_thumbnail, int read_all)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
exif_read_data() with streams test
3+
--SKIPIF--
4+
<?php if (!extension_loaded('exif')) print 'skip exif extension not available';?>
5+
--INI--
6+
output_handler=
7+
zlib.output_compression=0
8+
--FILE--
9+
<?php
10+
$fp = fopen(__DIR__ . '/image027.tiff', 'rb');
11+
12+
fseek($fp, 100, SEEK_SET);
13+
14+
exif_read_data($fp);
15+
16+
var_dump(ftell($fp) === 100);
17+
18+
fclose($fp);
19+
?>
20+
--EXPECT--
21+
bool(true)

0 commit comments

Comments
 (0)