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
1 change: 0 additions & 1 deletion .github/actions/apt-x32/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ runs:
libssl-dev:i386 \
libwebp-dev:i386 \
libxml2-dev:i386 \
libxml2-dev:i386 \
libxpm-dev:i386 \
libxslt1-dev:i386 \
firebird-dev:i386 \
Expand Down
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ PHP NEWS
. socket_set_option for multicast context throws a ValueError
when the socket family is not of AF_INET/AF_INET6 family. (David Carlier)

- Standard:
. Add HEIF/HEIC support to getimagesize. (Benstone Zhang)

- URI:
. Empty host handling is fixed. (Máté Kocsis)
. Error handling of Uri\WhatWg\Url::withHost() is fixed when the input
Expand Down
1 change: 1 addition & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ PHP 8.5 UPGRADE NOTES
process was terminated unexpectedly. In such cases, a warning is emitted
and the function returns false. Previously, these errors were silently
ignored. This change affects only the sendmail transport.
. getimagesize() now supports HEIF/HEIC images.

- XSL:
. The $namespace argument of XSLTProcessor::getParameter(),
Expand Down
5 changes: 5 additions & 0 deletions ext/standard/basic_functions.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,11 @@
* @cvalue IMAGE_FILETYPE_AVIF
*/
const IMAGETYPE_AVIF = UNKNOWN;
/**
* @var int
* @cvalue IMAGE_FILETYPE_HEIF
*/
const IMAGETYPE_HEIF = UNKNOWN;
/**
* @var int
* @cvalue IMAGE_FILETYPE_UNKNOWN
Expand Down
3 changes: 2 additions & 1 deletion ext/standard/basic_functions_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions ext/standard/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ PHPAPI const char php_sig_iff[4] = {'F','O','R','M'};
PHPAPI const char php_sig_ico[4] = {(char)0x00, (char)0x00, (char)0x01, (char)0x00};
PHPAPI const char php_sig_riff[4] = {'R', 'I', 'F', 'F'};
PHPAPI const char php_sig_webp[4] = {'W', 'E', 'B', 'P'};
PHPAPI const char php_sig_ftyp[4] = {'f', 't', 'y', 'p'};
PHPAPI const char php_sig_mif1[4] = {'m', 'i', 'f', '1'};
PHPAPI const char php_sig_heic[4] = {'h', 'e', 'i', 'c'};
PHPAPI const char php_sig_heix[4] = {'h', 'e', 'i', 'x'};

/* REMEMBER TO ADD MIME-TYPE TO FUNCTION php_image_type_to_mime_type */
/* PCX must check first 64bytes and byte 0=0x0a and byte2 < 0x06 */
Expand Down Expand Up @@ -1254,6 +1258,8 @@ PHPAPI char * php_image_type_to_mime_type(int image_type)
return "image/webp";
case IMAGE_FILETYPE_AVIF:
return "image/avif";
case IMAGE_FILETYPE_HEIF:
return "image/heif";
default:
case IMAGE_FILETYPE_UNKNOWN:
return "application/octet-stream"; /* suppose binary format */
Expand Down Expand Up @@ -1339,6 +1345,10 @@ PHP_FUNCTION(image_type_to_extension)
case IMAGE_FILETYPE_AVIF:
imgext = ".avif";
break;
case IMAGE_FILETYPE_HEIF:
imgext = ".heif";
break;
break;
}

if (imgext) {
Expand Down Expand Up @@ -1423,6 +1433,11 @@ PHPAPI int php_getimagetype(php_stream *stream, const char *input, char *filetyp
return IMAGE_FILETYPE_JP2;
}

if (twelve_bytes_read && !memcmp(filetype + 4, php_sig_ftyp, 4) &&
(!memcmp(filetype + 8, php_sig_mif1, 4) || !memcmp(filetype + 8, php_sig_heic, 4) || !memcmp(filetype + 8, php_sig_heix, 4))) {
return IMAGE_FILETYPE_HEIF;
}

if (!php_stream_rewind(stream) && php_is_image_avif(stream)) {
return IMAGE_FILETYPE_AVIF;
}
Expand Down Expand Up @@ -1515,6 +1530,11 @@ static void php_getimagesize_from_stream(php_stream *stream, char *input, zval *
case IMAGE_FILETYPE_AVIF:
result = php_handle_avif(stream);
break;
case IMAGE_FILETYPE_HEIF:
if (!php_stream_rewind(stream)) {
result = php_handle_avif(stream);
}
break;
default:
case IMAGE_FILETYPE_UNKNOWN:
break;
Expand Down
1 change: 1 addition & 0 deletions ext/standard/php_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ typedef enum
IMAGE_FILETYPE_ICO,
IMAGE_FILETYPE_WEBP,
IMAGE_FILETYPE_AVIF,
IMAGE_FILETYPE_HEIF,
/* WHEN EXTENDING: PLEASE ALSO REGISTER IN basic_function.stub.php */
IMAGE_FILETYPE_COUNT
} image_filetype;
Expand Down
19 changes: 18 additions & 1 deletion ext/standard/tests/image/getimagesize.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ GetImageSize()
var_dump($result);
?>
--EXPECT--
array(17) {
array(18) {
["test-1pix.bmp"]=>
array(6) {
[0]=>
Expand Down Expand Up @@ -216,6 +216,23 @@ array(17) {
["mime"]=>
string(9) "image/gif"
}
["test4pix.heic"]=>
array(7) {
[0]=>
int(54)
[1]=>
int(84)
[2]=>
int(20)
[3]=>
string(22) "width="54" height="84""
["bits"]=>
int(8)
["channels"]=>
int(3)
["mime"]=>
string(10) "image/heif"
}
["test4pix.iff"]=>
array(6) {
[0]=>
Expand Down
4 changes: 4 additions & 0 deletions ext/standard/tests/image/image_type_to_extension.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ image_type_to_extension()
"IMAGETYPE_XBM" => IMAGETYPE_XBM,
"IMAGETYPE_WEBP" => IMAGETYPE_WEBP,
"IMAGETYPE_AVIF" => IMAGETYPE_AVIF,
"IMAGETYPE_HEIF" => IMAGETYPE_HEIF,
);
foreach($constants as $name => $constant) {
printf("Constant: %s\n\tWith dot: %s\n\tWithout dot: %s\n", $name, image_type_to_extension($constant), image_type_to_extension($constant, false));
Expand Down Expand Up @@ -89,6 +90,9 @@ Constant: IMAGETYPE_WEBP
Constant: IMAGETYPE_AVIF
With dot: .avif
Without dot: avif
Constant: IMAGETYPE_HEIF
With dot: .heif
Without dot: heif
bool(false)
bool(false)
Done
4 changes: 3 additions & 1 deletion ext/standard/tests/image/image_type_to_mime_type.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ image_type_to_mime_type()
var_dump($result);
?>
--EXPECT--
array(17) {
array(18) {
["test-1pix.bmp"]=>
string(9) "image/bmp"
["test12pix.webp"]=>
Expand All @@ -49,6 +49,8 @@ array(17) {
string(10) "image/webp"
["test4pix.gif"]=>
string(9) "image/gif"
["test4pix.heic"]=>
string(10) "image/heif"
["test4pix.iff"]=>
string(9) "image/iff"
["test4pix.png"]=>
Expand Down
4 changes: 3 additions & 1 deletion ext/standard/tests/image/image_type_to_mime_type_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ $image_types = array (
IMAGETYPE_WBMP,
IMAGETYPE_JPEG2000,
IMAGETYPE_XBM,
IMAGETYPE_WEBP
IMAGETYPE_WEBP,
IMAGETYPE_HEIF,
);

foreach($image_types as $image_type) {
Expand Down Expand Up @@ -51,5 +52,6 @@ string(18) "image/vnd.wap.wbmp"
string(24) "application/octet-stream"
string(9) "image/xbm"
string(10) "image/webp"
string(10) "image/heif"

Done image_type_to_mime_type() test
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,7 @@ string\(10\) "image\/webp"
string\(10\) "image\/avif"

-- Iteration 20 --
string\(10\) "image\/heif"

-- Iteration 21 --
string\(24\) "application\/octet-stream"
Binary file added ext/standard/tests/image/test4pix.heic
Binary file not shown.
2 changes: 1 addition & 1 deletion sapi/fuzzer/fuzzer-sapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static const char HARDCODED_INI[] =
"allow_url_include=0\n"
"allow_url_fopen=0\n"
"open_basedir=/tmp\n"
"disable_functions=dl,mail,mb_send_mail"
"disable_functions=dl,mail,mb_send_mail,set_error_handler"
",shell_exec,exec,system,proc_open,popen,passthru,pcntl_exec"
",chdir,chgrp,chmod,chown,copy,file_put_contents,lchgrp,lchown,link,mkdir"
",move_uploaded_file,rename,rmdir,symlink,tempname,touch,unlink,fopen"
Expand Down