Skip to content

Commit d1537e5

Browse files
committed
Fixed bug #79046
1 parent 9406361 commit d1537e5

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ PHP NEWS
2020
- CURL:
2121
. Fixed bug #79033 (Curl timeout error with specific url and post). (cmb)
2222

23+
- Exif:
24+
. Fixed bug #79046 (NaN to int cast undefined behavior in exif). (Nikita)
25+
2326
- Fileinfo:
2427
. Fixed bug #74170 (locale information change after mime_content_type).
2528
(Sergei Turchanov)

ext/exif/exif.c

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

17001700
/* Use saturation for out of bounds values to avoid UB */
17011701
static size_t float_to_size_t(float x) {
1702-
if (x < 0.0f) {
1702+
if (x < 0.0f || zend_isnan(x)) {
17031703
return 0;
17041704
} else if (x > (float) SIZE_MAX) {
17051705
return SIZE_MAX;
@@ -1709,7 +1709,7 @@ static size_t float_to_size_t(float x) {
17091709
}
17101710

17111711
static size_t double_to_size_t(double x) {
1712-
if (x < 0.0) {
1712+
if (x < 0.0 || zend_isnan(x)) {
17131713
return 0;
17141714
} else if (x > (double) SIZE_MAX) {
17151715
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)