United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4528643 : Native JPEG code makes JNI calls in scope of GetPrimitiveArrayCritical

Details
Type:
Bug
Submit Date:
2001-11-17
Status:
Resolved
Updated Date:
2011-05-26
Project Name:
JDK
Resolved Date:
2006-05-02
Component:
client-libs
OS:
linux,generic,windows_xp
Sub-Component:
javax.imageio
CPU:
x86,generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
1.4.0,1.4.2,5.0
Fixed Versions:

Related Reports
Backport:
Backport:
Duplicate:
Duplicate:
Duplicate:
Relates:

Sub Tasks

Description
Certain methods in imageioJPEG.c (the glue code between the IJG native JPEG
libraries and the Image I/O API) such as readImageHeader(), readImage(),
writeImageHeader(), and writeImage() make JNI calls in the scope of
Get/ReleasePrimitiveArrayCritical.  Most Java upcalls in the file have been
correctly surrounded with RELEASE/GET_ARRAYS macros, but a few cases fell
through the cracks.

Running any application that reads or writes JPEG images with the non-standard
-Xcheck:jni flag causes the following error (or something similar):

FATAL ERROR in native method: Calling other JNI functions in the scope of Get/ReleasePrimitiveArrayCritical or Get/ReleaseStringCritical
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImageHeader(Native Method)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.readNativeHeader(JPEGImageReader.java:545)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.checkTablesOnly(JPEGImageReader.java:300)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.gotoImage(JPEGImageReader.java:422)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.readHeader(JPEGImageReader.java:538)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:871)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:855)
	at javax.imageio.ImageIO.read(ImageIO.java:1317)
	at javax.imageio.ImageIO.read(ImageIO.java:1241)
	at Test.<init>(Test.java:29)
	at Test.main(Test.java:40)

These problem areas are unlikely to cause problems, but we should try to
conform to the JNI specs, which mandate that no JNI upcalls be made inside
of a critical section.
###@###.### 2001-11-16

                                    

Comments
EVALUATION

The reason of -Xcheck:jni warnings in readImageHeader() method was 
 invocation of the setImageData() method in the critical section.

 Numerous warnings in the writeImage() method were caused by handling
 encoding tables (that requires number of jni calls) inside critical
 section. However, we can get output buffer array later, after
 completion of encoding tables processing.
                                     
2006-04-20
EVALUATION

We have an important demo app that loads a ton of JPEG files and triggers
this bug, so when -Xcheck:jni is enabled it makes it very difficult to see
if there are any JNI-related issues other than the one reported here.  We should
fix this for Mustang if possible.  The most reproducible case is the one
reported in the description field: in imageioJPEG.c, in the readImageHeader()
method we call read_icc_profile() within a GET/RELEASE pair, which in turn calls
into various CMM functions that make JNI calls.  For each one of those JNI calls
another -Xcheck:jni warning is emitted which causes a lot of confusing spew to
the console.  We should be able to fix this by calling RELEASE_ARRAYS() before
the CallVoidMethod(setImageDataID).  It should be easy to reproduce this bug by
reading a JPEG image with an embedded color profile.
                                     
2006-04-13
SUGGESTED FIX

Unfortunately the line numbers above are no longer accurate, so we should
probably look through the code for possible problem areas.
                                     
2006-04-13
PUBLIC COMMENTS

The native JPEG code for Image I/O is making a number of JNI method calls
when it has a lock (inside of a Get/ReleasePrimitiveArrayCritical pair).  This
is unlikely to cause problems in any application, but the offending code
should be reworked so we conform to the JNI specification.
                                     
2004-08-24
EVALUATION

We should make sure all Java upcalls in imageioJPEG.c are surrounded with a
RELEASE/GET_ARRAYS pair (as enumerated in the suggested fix).  We can use the
non-standard -Xcheck:jni flag to verify that all offending code has been
properly reorganized.
###@###.### 2001-11-16
                                     
2001-11-16
SUGGESTED FIX

Ensure all JNI method calls in imageioJPEG.c are appropriately wrapped in a
RELEASE/GET_ARRAYS macro pair.  The method calls on the following lines in
imageioJPEG.c are suspect: 1608, 1843, 1848, 1930, 2320-2344, and 2486-2604.
###@###.### 2001-11-16
                                     
2001-11-16



Hardware and Software, Engineered to Work Together