Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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