On Mon, 16 Nov 2026 11:35:03 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). Part of the problem is that the macro can't enforce what is being passed to it, nor how the app then uses the values. It has to be used properly. And although not likely here, if someone passes a 64-bit long to the macro .. those casts could be a problem .. But perhaps we can make it a bit safer. SAFE_TO_ALLOC is defined in the splash screen code. realistically, splashscreen should not be dealing with anything that overflows a signed int. This is an image that fits on a screen. And the idea is to load and display fast. so realistically anything bigger than 2,000 x 2,000 is unlikely If we allow 4 bytes per pixel an int could accommodate a 20,000 x 20,000 image. If someone has something bigger than that ... for a splashscreen .. something is up. So IMO we could for this code insist / just check that a signed int does not overflow. at that point it really becomes "SAFE_TO_MULT_AND_STORE_IN_INT". We could not do this 'in general' but knowing the use case for splash screen I think it OK. if this were in a 32 bit app, the current malloc would fail anyway on many values that currently pass SAFE_TO_ALLOC. ------------- PR Comment: https://git.openjdk.org/jdk/pull/33915#issuecomment-6990181960
