Skip to content

Commit

Permalink
8299628: BMP top-down images fail to load after JDK-8289336
Browse files Browse the repository at this point in the history
Reviewed-by: aghaisas, kcr
  • Loading branch information
arapte authored and kevinrushforth committed Jan 17, 2023
1 parent e3b0925 commit d60d9ef
Showing 1 changed file with 9 additions and 3 deletions.
Expand Up @@ -124,10 +124,16 @@ final class BitmapInfoHeader {
if (biWidth <= 0) {
throw new IOException("Bad BMP image width, must be > 0!");
}
if (biHeight <= 0) {
throw new IOException("Bad BMP image height, must be > 0!");
// If biHeight is negative, the bitmap is a top-down DIB
// See: https://learn.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapinfoheader

int height = Math.abs(biHeight);

if (height == 0) {
throw new IOException("Bad BMP image height, must be != 0!");
}
if (biWidth >= (Integer.MAX_VALUE / biHeight)) {

if (biWidth >= (Integer.MAX_VALUE / height)) {
throw new IOException("Bad BMP image size!");
}

Expand Down

0 comments on commit d60d9ef

Please sign in to comment.