#731435 warning: iteration 55823u invokes undefined behavior [-Waggressive-loop-optimizations]

Package:
gdcm
Source:
gdcm
Submitter:
Mathieu Malaterre
Date:
2024-09-14 11:03:02 UTC
Severity:
normal
Tags:
#731435#5
Date:
2013-12-05 13:00:59 UTC
From:
To:
gdcm currently compiles with:

cd /«PKGBUILDDIR»/obj-i486-linux-gnu/Utilities/gdcmjpeg/8 &&
/usr/bin/cc  -Dgdcmjpeg8_EXPORTS -g -O2 -fstack-protector
--param=ssp-buffer-size=4 -Wformat -Werror=format-security
-D_FORTIFY_SOURCE=2  -fPIC -I/«PKGBUILDDIR»/Utilities/gdcmjpeg/8
-I/«PKGBUILDDIR»/obj-i486-linux-gnu/Utilities/gdcmjpeg/8
-I/«PKGBUILDDIR»/obj-i486-linux-gnu/Utilities/gdcmjpeg    -o
CMakeFiles/gdcmjpeg8.dir/__/jccolor.c.o   -c
/«PKGBUILDDIR»/Utilities/gdcmjpeg/jccolor.c
/«PKGBUILDDIR»/Utilities/gdcmjpeg/jccolor.c: In function 'rgb_ycc_start':
/«PKGBUILDDIR»/Utilities/gdcmjpeg/jccolor.c:99:43: warning: iteration
55823u invokes undefined behavior [-Waggressive-loop-optimizations]
     rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
                                           ^
/«PKGBUILDDIR»/Utilities/gdcmjpeg/jccolor.c:97:3: note: containing loop
   for (i = 0; i <= MAXJSAMPLE; i++) {
   ^
/usr/bin/cmake -E cmake_progress_report
/«PKGBUILDDIR»/obj-i486-linux-gnu/CMakeFiles

#731435#14
Date:
2020-04-05 18:22:08 UTC
From:
To:
This has already been reported upstream, and it seems exactly the same
as #731433, which was fixed upstream in DCMTK:

https://support.dcmtk.org/redmine/issues/759

Berto

#731435#19
Date:
2020-04-06 08:29:35 UTC
From:
To:
#731435#26
Date:
2020-04-06 09:07:35 UTC
From:
To:
I have to say that I don't see how the changes to jccolor.c solve the
problem ... the warning that we have is about this line:

     rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;

This is round(0.58700 * 65536) * 55823 = 2147510810, which exceeds
INT32_MAX and therefore cannot be stored in rgb_ycc_tab, no matter how
many casts you use.

Berto

#731435#33
Date:
2024-09-14 11:01:17 UTC
From:
To:
Control: tags -1 - patch

I agree, I tested the patch and the warnings remain:

/build/gdcm-3.0.24/Utilities/gdcmjpeg/jccolor.c: In function ‘rgb_ycc_start’:
/build/gdcm-3.0.24/Utilities/gdcmjpeg/jccolor.c:112:43: warning: iteration 55823 invokes undefined behavior [-Waggressive-loop-optimizations]
   112 |     rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
       |                                           ^
/build/gdcm-3.0.24/Utilities/gdcmjpeg/jccolor.c:110:17: note: within this loop