Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions ext/exif/exif.c
Original file line number Diff line number Diff line change
Expand Up @@ -4699,7 +4699,6 @@ PHP_FUNCTION(exif_read_data)
PHP_FUNCTION(exif_thumbnail)
{
bool ret;
int arg_c = ZEND_NUM_ARGS();
image_info_type ImageInfo;
zval *stream;
zval *z_width = NULL, *z_height = NULL, *z_imagetype = NULL;
Expand Down Expand Up @@ -4731,7 +4730,7 @@ PHP_FUNCTION(exif_thumbnail)
RETURN_THROWS();
}

if (CHECK_NULL_PATH(Z_STRVAL_P(stream), Z_STRLEN_P(stream))) {
if (zend_str_has_nul_byte(Z_STR_P(stream))) {
zend_argument_value_error(1, "must not contain any null bytes");
RETURN_THROWS();
}
Expand All @@ -4756,17 +4755,19 @@ PHP_FUNCTION(exif_thumbnail)
exif_error_docref(NULL EXIFERR_CC, &ImageInfo, E_NOTICE, "Returning thumbnail(%d)", ImageInfo.Thumbnail.size);
#endif

ZVAL_STRINGL(return_value, ImageInfo.Thumbnail.data, ImageInfo.Thumbnail.size);
if (arg_c >= 3) {
if (!ImageInfo.Thumbnail.width || !ImageInfo.Thumbnail.height) {
if (!exif_scan_thumbnail(&ImageInfo)) {
ImageInfo.Thumbnail.width = ImageInfo.Thumbnail.height = 0;
}
RETVAL_STRINGL(ImageInfo.Thumbnail.data, ImageInfo.Thumbnail.size);
if ((z_width || z_height) && (!ImageInfo.Thumbnail.width || !ImageInfo.Thumbnail.height)) {
if (!exif_scan_thumbnail(&ImageInfo)) {
ImageInfo.Thumbnail.width = ImageInfo.Thumbnail.height = 0;
}
}
if (z_width) {
ZEND_TRY_ASSIGN_REF_LONG(z_width, ImageInfo.Thumbnail.width);
}
if (z_height) {
ZEND_TRY_ASSIGN_REF_LONG(z_height, ImageInfo.Thumbnail.height);
}
if (arg_c >= 4) {
if (z_imagetype) {
ZEND_TRY_ASSIGN_REF_LONG(z_imagetype, ImageInfo.Thumbnail.filetype);
}

Expand Down
12 changes: 12 additions & 0 deletions ext/exif/tests/exif_thumbnail_streams.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@ $fp = fopen(__DIR__ . '/sony.jpg', 'rb');

var_dump(strlen(exif_thumbnail($fp)));

exif_thumbnail($fp, width: $width);
var_dump($width);

exif_thumbnail($fp, height: $height);
var_dump($height);

exif_thumbnail($fp, image_type: $image_type);
var_dump($image_type == IMAGETYPE_JPEG);

fclose($fp);
?>
--EXPECT--
int(4150)
int(160)
int(90)
bool(true)