]> granicus.if.org Git - php/commitdiff
Avoid float to int cast UB in exif
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 9 Oct 2019 15:33:01 +0000 (17:33 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 9 Oct 2019 15:33:29 +0000 (17:33 +0200)
ext/exif/exif.c

index b47e55fba1b138075aec5e0cc9f594d9e536e92c..f961f44a46c61a1918cf57d4575c39080c6d35b1 100644 (file)
@@ -4598,8 +4598,9 @@ PHP_FUNCTION(exif_read_data)
                exif_iif_add_fmt(&ImageInfo, SECTION_COMPUTED, "CCDWidth", "%dmm", (int)ImageInfo.CCDWidth);
        }
        if(ImageInfo.ExposureTime>0) {
-               if(ImageInfo.ExposureTime <= 0.5) {
-                       exif_iif_add_fmt(&ImageInfo, SECTION_COMPUTED, "ExposureTime", "%0.3F s (1/%d)", ImageInfo.ExposureTime, (int)(0.5 + 1/ImageInfo.ExposureTime));
+               float recip_exposure_time = 0.5f + 1.0f/ImageInfo.ExposureTime;
+               if (ImageInfo.ExposureTime <= 0.5 && recip_exposure_time < INT_MAX) {
+                       exif_iif_add_fmt(&ImageInfo, SECTION_COMPUTED, "ExposureTime", "%0.3F s (1/%d)", ImageInfo.ExposureTime, (int) recip_exposure_time);
                } else {
                        exif_iif_add_fmt(&ImageInfo, SECTION_COMPUTED, "ExposureTime", "%0.3F s", ImageInfo.ExposureTime);
                }