提交 c05a9733 编写于 作者: J jdv

8162461: Hang due to JNI up-call made whilst holding JNI critical lock

Reviewed-by: prr, aghaisas
上级 d0c48fa3
/* /*
* Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -553,30 +553,43 @@ sun_jpeg_error_exit (j_common_ptr cinfo) ...@@ -553,30 +553,43 @@ sun_jpeg_error_exit (j_common_ptr cinfo)
METHODDEF(void) METHODDEF(void)
sun_jpeg_output_message (j_common_ptr cinfo) sun_jpeg_output_message (j_common_ptr cinfo)
{ {
char buffer[JMSG_LENGTH_MAX]; char buffer[JMSG_LENGTH_MAX];
jstring string; jstring string;
imageIODataPtr data = (imageIODataPtr) cinfo->client_data; imageIODataPtr data = (imageIODataPtr) cinfo->client_data;
JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
jobject theObject; jobject theObject;
/* Create the message */ /* Create the message */
(*cinfo->err->format_message) (cinfo, buffer); (*cinfo->err->format_message) (cinfo, buffer);
// Create a new java string from the message // Create a new java string from the message
string = (*env)->NewStringUTF(env, buffer); string = (*env)->NewStringUTF(env, buffer);
CHECK_NULL(string); CHECK_NULL(string);
theObject = data->imageIOobj; theObject = data->imageIOobj;
if (cinfo->is_decompressor) { if (cinfo->is_decompressor) {
(*env)->CallVoidMethod(env, theObject, struct jpeg_source_mgr *src = ((j_decompress_ptr)cinfo)->src;
JPEGImageReader_warningWithMessageID, RELEASE_ARRAYS(env, data, src->next_input_byte);
string); (*env)->CallVoidMethod(env, theObject,
} else { JPEGImageReader_warningWithMessageID,
(*env)->CallVoidMethod(env, theObject, string);
JPEGImageWriter_warningWithMessageID, if ((*env)->ExceptionOccurred(env)
string); || !GET_ARRAYS(env, data, &(src->next_input_byte))) {
} cinfo->err->error_exit(cinfo);
}
} else {
struct jpeg_destination_mgr *dest = ((j_compress_ptr)cinfo)->dest;
RELEASE_ARRAYS(env, data, (const JOCTET *)(dest->next_output_byte));
(*env)->CallVoidMethod(env, theObject,
JPEGImageWriter_warningWithMessageID,
string);
if ((*env)->ExceptionOccurred(env)
|| !GET_ARRAYS(env, data,
(const JOCTET **)(&dest->next_output_byte))) {
cinfo->err->error_exit(cinfo);
}
}
} }
/* End of verbatim copy from jpegdecoder.c */ /* End of verbatim copy from jpegdecoder.c */
...@@ -1043,6 +1056,7 @@ imageio_fill_suspended_buffer(j_decompress_ptr cinfo) ...@@ -1043,6 +1056,7 @@ imageio_fill_suspended_buffer(j_decompress_ptr cinfo)
if (!GET_ARRAYS(env, data, &(src->next_input_byte))) { if (!GET_ARRAYS(env, data, &(src->next_input_byte))) {
cinfo->err->error_exit((j_common_ptr) cinfo); cinfo->err->error_exit((j_common_ptr) cinfo);
} }
RELEASE_ARRAYS(env, data, src->next_input_byte);
return; return;
} }
...@@ -1798,9 +1812,14 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImageHeader ...@@ -1798,9 +1812,14 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImageHeader
cinfo->out_color_space, cinfo->out_color_space,
cinfo->num_components, cinfo->num_components,
profileData); profileData);
if ((*env)->ExceptionOccurred(env)
|| !GET_ARRAYS(env, data, &(src->next_input_byte))) {
cinfo->err->error_exit((j_common_ptr) cinfo);
}
if (reset) { if (reset) {
jpeg_abort_decompress(cinfo); jpeg_abort_decompress(cinfo);
} }
RELEASE_ARRAYS(env, data, src->next_input_byte);
} }
return retval; return retval;
...@@ -2011,6 +2030,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImage ...@@ -2011,6 +2030,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImage
jpeg_start_decompress(cinfo); jpeg_start_decompress(cinfo);
if (numBands != cinfo->output_components) { if (numBands != cinfo->output_components) {
RELEASE_ARRAYS(env, data, src->next_input_byte);
JNU_ThrowByName(env, "javax/imageio/IIOException", JNU_ThrowByName(env, "javax/imageio/IIOException",
"Invalid argument to native readImage"); "Invalid argument to native readImage");
return data->abortFlag; return data->abortFlag;
...@@ -2019,6 +2039,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImage ...@@ -2019,6 +2039,7 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImage
if (cinfo->output_components <= 0 || if (cinfo->output_components <= 0 ||
cinfo->image_width > (0xffffffffu / (unsigned int)cinfo->output_components)) cinfo->image_width > (0xffffffffu / (unsigned int)cinfo->output_components))
{ {
RELEASE_ARRAYS(env, data, src->next_input_byte);
JNU_ThrowByName(env, "javax/imageio/IIOException", JNU_ThrowByName(env, "javax/imageio/IIOException",
"Invalid number of output components"); "Invalid number of output components");
return data->abortFlag; return data->abortFlag;
...@@ -2042,15 +2063,24 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImage ...@@ -2042,15 +2063,24 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImage
// the first interesting pass. // the first interesting pass.
jpeg_start_output(cinfo, cinfo->input_scan_number); jpeg_start_output(cinfo, cinfo->input_scan_number);
if (wantUpdates) { if (wantUpdates) {
RELEASE_ARRAYS(env, data, src->next_input_byte);
(*env)->CallVoidMethod(env, this, (*env)->CallVoidMethod(env, this,
JPEGImageReader_passStartedID, JPEGImageReader_passStartedID,
cinfo->input_scan_number-1); cinfo->input_scan_number-1);
if ((*env)->ExceptionOccurred(env)
|| !GET_ARRAYS(env, data, &(src->next_input_byte))) {
cinfo->err->error_exit((j_common_ptr) cinfo);
}
} }
} else if (wantUpdates) { } else if (wantUpdates) {
RELEASE_ARRAYS(env, data, src->next_input_byte);
(*env)->CallVoidMethod(env, this, (*env)->CallVoidMethod(env, this,
JPEGImageReader_passStartedID, JPEGImageReader_passStartedID,
0); 0);
if ((*env)->ExceptionOccurred(env)
|| !GET_ARRAYS(env, data, &(src->next_input_byte))) {
cinfo->err->error_exit((j_common_ptr) cinfo);
}
} }
// Skip until the first interesting line // Skip until the first interesting line
...@@ -2138,8 +2168,13 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImage ...@@ -2138,8 +2168,13 @@ Java_com_sun_imageio_plugins_jpeg_JPEGImageReader_readImage
done = TRUE; done = TRUE;
} }
if (wantUpdates) { if (wantUpdates) {
RELEASE_ARRAYS(env, data, src->next_input_byte);
(*env)->CallVoidMethod(env, this, (*env)->CallVoidMethod(env, this,
JPEGImageReader_passCompleteID); JPEGImageReader_passCompleteID);
if ((*env)->ExceptionOccurred(env)
|| !GET_ARRAYS(env, data, &(src->next_input_byte))) {
cinfo->err->error_exit((j_common_ptr) cinfo);
}
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册