ext/exif: Minor refactoring of exif_thumbnail() (#16111)

This commit is contained in:
Gina Peter Banyard 2024-09-29 15:57:04 +01:00 committed by GitHub
parent fec2055af2
commit 291eef285c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 9 deletions

View file

@ -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;
@ -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();
}
@ -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);
}

View file

@ -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)