On Fri, 20 Nov 2026 07:29:10 GMT, Timofei Fedotov <[email protected]> wrote:
>> SplashDecodeJpeg() allocates bitmap storage using stride * height as a >> signed int expression. SAFE_TO_ALLOC checks an unsigned 32-bit bound, so it >> can accept a mathematical product above INT_MAX. The allocation expression >> then has signed overflow and undefined behavior. >> >> If bitmap allocation fails, the function frees splash->frames but leaves its >> pointer and frameCount unchanged. The buffer-allocation failure path has the >> same ownership problem. A subsequent SplashCleanup(), including cleanup >> after an unsuccessful startup splash decode, can read freed frame storage >> and attempt to free it again. >> >> An example size is width 65500, height 16000, and four bytes per pixel: the >> product is 4192000000, which passes the existing unsigned size guard but >> exceeds INT_MAX. >> >> Expected behavior: size calculation must not overflow signed arithmetic, and >> failure must leave no freed frame storage reachable by cleanup. >> >> --------- >> - [x] I confirm that I make this contribution in accordance with the >> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai). > > Timofei Fedotov has updated the pull request incrementally with one > additional commit since the last revision: > > Update copyright years I'm not sure why, but I don't see a GHA build for your latest changes. And alas, when I try it I get compilation errors src/java.desktop/share/native/libsplashscreen/splashscreen_gif.c:109:10: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare] 109 | if (!SAFE_TO_ALLOC(gif->ImageCount, sizeof(SplashImage*))) { | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/java.desktop/share/native/libsplashscreen/splashscreen_impl.h:190:11: note: expanded from macro 'SAFE_TO_ALLOC' 190 | ((c) <= INT_MAX / (sz))) | ~ ^ ~~~~~~~~~~~~~~ 1 error generated. src/java.desktop/share/native/libsplashscreen/splashscreen_jpeg.c:160:10: error: comparison of integers of different signs: 'JDIMENSION' (aka 'unsigned int') and 'int' [-Werror,-Wsign-compare] 160 | if (!SAFE_TO_ALLOC(cinfo->output_width, cinfo->output_components)) { | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ src/java.desktop/share/native/libsplashscreen/splashscreen_impl.h:190:11: note: expanded from macro 'SAFE_TO_ALLOC' 190 | ((c) <= INT_MAX / (sz))) | ~ ^ ~~~~~~~~~~~~~~ Did you not see such an error locally ? So the comparisons are agaisnt the same type. I think in the macro after passing the > 0 test each value should be promoted to size_t, since that is what sizeof() will return and so should be at least as safe. That fixes it for me on macOS #define SAFE_TO_ALLOC(c, sz) \ (((c) > 0) && ((sz) > 0) && \ ((size_t)(c) <= (size_t)INT_MAX / (size_t)(sz))) Do you see any problems with that ? ------------- PR Comment: https://git.openjdk.org/jdk/pull/33915#issuecomment-7086583217
