On Mon, 23 Nov 2026 06:15:57 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: > > Include limits.h for INT_MAX Code change looks good to me apart from minor update. Building and testing is green with latest change. src/java.desktop/share/native/libsplashscreen/splashscreen_png.c line 174: > 172: convertRect(&srcRect, &dstRect, CVT_COPY); > 173: > 174: SplashInitFrameShape(splash, 0); We have scenarios where allocation inside `SplashInitFrameShape()` can fail and we return before assigning any value to `splash->frames[imageIndex].hRgn` in `src/java.desktop/windows/native/libsplashscreen/splashscreen_sys.c`. Subsequent cleanup can hit this uninitialized object. In `src/java.desktop/unix/native/libsplashscreen/splashscreen_sys.c` this is taken care by initializing `frame->rects` and `frame->numRects`. For windows we can do similar thing and initialize `splash->frames[imageIndex].hRgn = NULL` in `SplashInitFrameShape()`. ------------- PR Review: https://git.openjdk.org/jdk/pull/33915#pullrequestreview-6053755565 PR Review Comment: https://git.openjdk.org/jdk/pull/33915#discussion_r4691915658
