Skip to content

Commit d21ad4d

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fixed bug #79046
2 parents 1ab9d62 + d1537e5 commit d21ad4d

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

ext/exif/exif.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,7 +1669,7 @@ static int exif_rewrite_tag_format_to_unsigned(int format)
16691669

16701670
/* Use saturation for out of bounds values to avoid UB */
16711671
static size_t float_to_size_t(float x) {
1672-
if (x < 0.0f) {
1672+
if (x < 0.0f || zend_isnan(x)) {
16731673
return 0;
16741674
} else if (x > (float) SIZE_MAX) {
16751675
return SIZE_MAX;
@@ -1679,7 +1679,7 @@ static size_t float_to_size_t(float x) {
16791679
}
16801680

16811681
static size_t double_to_size_t(double x) {
1682-
if (x < 0.0) {
1682+
if (x < 0.0 || zend_isnan(x)) {
16831683
return 0;
16841684
} else if (x > (double) SIZE_MAX) {
16851685
return SIZE_MAX;

ext/exif/tests/bug79046.phpt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Bug #79046: NaN to int cast undefined behavior in exif
3+
--FILE--
4+
<?php
5+
var_dump(exif_read_data('data://image/tiff;base64,TU0AKgAAAA7//wAAANUAAQERAAsAAAABAAD4fwAAAA4A'));
6+
?>
7+
--EXPECT--
8+
array(8) {
9+
["FileDateTime"]=>
10+
int(0)
11+
["FileSize"]=>
12+
int(33)
13+
["FileType"]=>
14+
int(8)
15+
["MimeType"]=>
16+
string(10) "image/tiff"
17+
["SectionsFound"]=>
18+
string(24) "ANY_TAG, IFD0, THUMBNAIL"
19+
["COMPUTED"]=>
20+
array(2) {
21+
["IsColor"]=>
22+
int(0)
23+
["ByteOrderMotorola"]=>
24+
int(1)
25+
}
26+
["StripOffsets"]=>
27+
float(NAN)
28+
["THUMBNAIL"]=>
29+
array(1) {
30+
["StripOffsets"]=>
31+
float(NAN)
32+
}
33+
}

0 commit comments

Comments
 (0)