Skip to content

Commit

Permalink
8298093: improve cleanup and error handling of awt_parseColorModel in…
Browse files Browse the repository at this point in the history
… awt_parseImage.c

Reviewed-by: lucy, clanger
  • Loading branch information
MBaesken committed Dec 15, 2022
1 parent 5f63f7a commit 98fa48c
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions src/java.desktop/share/native/libawt/awt/image/awt_parseImage.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -454,6 +454,7 @@ int awt_parseColorModel (JNIEnv *env, jobject jcmodel, int imageType,

int i;
static jobject s_jdefCM = NULL;
cmP->nBits = NULL;

if (JNU_IsNull(env, jcmodel)) {
JNU_ThrowNullPointerException(env, "null ColorModel object");
Expand Down Expand Up @@ -485,7 +486,6 @@ int awt_parseColorModel (JNIEnv *env, jobject jcmodel, int imageType,
return -1;
}

cmP->nBits = NULL;
if (SAFE_TO_ALLOC_2(cmP->numComponents, sizeof(jint))) {
cmP->nBits = (jint *)malloc(cmP->numComponents * sizeof(jint));
}
Expand All @@ -508,7 +508,9 @@ int awt_parseColorModel (JNIEnv *env, jobject jcmodel, int imageType,
cmP->csType = (*env)->GetIntField(env, cmP->jcmodel, g_CMcsTypeID);

cmP->cmType = getColorModelType(env, jcmodel);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
if ((*env)->ExceptionCheck(env)) {
goto cleanup;
}

cmP->isDefaultCM = FALSE;
cmP->isDefaultCompatCM = FALSE;
Expand All @@ -530,14 +532,21 @@ int awt_parseColorModel (JNIEnv *env, jobject jcmodel, int imageType,
if (s_jdefCM == NULL) {
jobject defCM;
jclass jcm = (*env)->FindClass(env, "java/awt/image/ColorModel");
CHECK_NULL_RETURN(jcm, -1);
if (jcm == NULL) {
goto cleanup;
}
defCM = (*env)->CallStaticObjectMethod(env, jcm,
g_CMgetRGBdefaultMID, NULL);
if ((*env)->ExceptionCheck(env)) {
(*env)->ExceptionClear(env);
JNU_ThrowNullPointerException(env, "Unable to find default CM");
goto cleanup;
}
s_jdefCM = (*env)->NewGlobalRef(env, defCM);
if (defCM == NULL || s_jdefCM == NULL) {
(*env)->ExceptionClear(env);
JNU_ThrowNullPointerException(env, "Unable to find default CM");
return -1;
goto cleanup;
}
}
cmP->isDefaultCM = ((*env)->IsSameObject(env, s_jdefCM, jcmodel));
Expand All @@ -549,12 +558,12 @@ int awt_parseColorModel (JNIEnv *env, jobject jcmodel, int imageType,
if (cmP->csType != java_awt_color_ColorSpace_TYPE_RGB ||
!cmP->is_sRGB)
{
return -1;
goto cleanup;
}

for (i = 0; i < cmP->numComponents; i++) {
if (cmP->nBits[i] != 8) {
return -1;
goto cleanup;
}
}
}
Expand All @@ -572,7 +581,7 @@ int awt_parseColorModel (JNIEnv *env, jobject jcmodel, int imageType,
cmP->jrgb,
NULL);
if (rgb == NULL) {
return -1;
goto cleanup;
}
for (i=0; i < cmP->mapSize; i++) {
if ((rgb[i]&0xff000000) == 0) {
Expand All @@ -590,6 +599,10 @@ int awt_parseColorModel (JNIEnv *env, jobject jcmodel, int imageType,
}

return 1;

cleanup:
free(cmP->nBits);
return -1;
}

void awt_freeParsedRaster(RasterS_t *rasterP, int freeRasterP) {
Expand Down

5 comments on commit 98fa48c

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk17u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 98fa48c Dec 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken the backport was successfully created on the branch MBaesken-backport-98fa48c3 in my personal fork of openjdk/jdk17u-dev. To create a pull request with this backport targeting openjdk/jdk17u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 98fa48c3 from the openjdk/jdk repository.

The commit being backported was authored by Matthias Baesken on 15 Dec 2022 and was reviewed by Lutz Schmidt and Christoph Langer.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk17u-dev:

$ git fetch https://github.com/openjdk-bots/jdk17u-dev MBaesken-backport-98fa48c3:MBaesken-backport-98fa48c3
$ git checkout MBaesken-backport-98fa48c3
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk17u-dev MBaesken-backport-98fa48c3

@MBaesken
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 98fa48c Jan 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MBaesken the backport was successfully created on the branch MBaesken-backport-98fa48c3 in my personal fork of openjdk/jdk11u-dev. To create a pull request with this backport targeting openjdk/jdk11u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 98fa48c3 from the openjdk/jdk repository.

The commit being backported was authored by Matthias Baesken on 15 Dec 2022 and was reviewed by Lutz Schmidt and Christoph Langer.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk11u-dev:

$ git fetch https://github.com/openjdk-bots/jdk11u-dev MBaesken-backport-98fa48c3:MBaesken-backport-98fa48c3
$ git checkout MBaesken-backport-98fa48c3
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk11u-dev MBaesken-backport-98fa48c3

Please sign in to comment.