# HG changeset patch # User Andrew John Hughes # Date 1378235306 -3600 # Node ID 222321136c4823e1861aeee3e843f94a9d58cfe9 # Parent 3c193afea5f3587d516f672e1fb08d029eba140c Backport a number of JPEG fixes from 7u. S4893408: JPEGReader throws IllegalArgException when setting the destination to BYTE_GRAY S6631559: Registration of ImageIO plugins should not cause loading of jpeg.dlli and cmm.dll S6791502: IIOException "Invalid icc profile" on jpeg after update from JDK5 to JDK6 S6793818: JpegImageReader is too greedy creating color profiles S6888215: memory leak in jpeg plugin S6989760: cmm native compiler warnings S6989774: imageio compiler warnings in native code S7013519: [parfait] Integer overflows in 2D code S7018912: [parfait] potential buffer overruns in imageio jpeg S8005194: [parfait] #353 sun/awt/image/jpeg/imageioJPEG.c Memory leak of pointer 'scale' allocated with calloc() S8020983, RH976897: OutOfMemoryError caused by non garbage collected JPEGImageWriter Instances 2013-08-30 Andrew John Hughes * Makefile.am: (ICEDTEA_PATCHES): Add new patches. * NEWS: Updated with new patches. * patches/imageiojpeg_sync.patch: Bring in changes to imageioJPEG.c made between the start of OpenJDK 6 and the start of OpenJDK 7's hg repositories. * patches/libraries.patch: Updated against patches below. * patches/openjdk/4893408-jpegreader_byte_gray.patch, * patches/openjdk/6631559-dont_load_libjpeg_to_register_imageio_plugins.patch, * patches/openjdk/6791502-invalid_icc_profile.patch, * patches/openjdk/6793818-jpegimagereader_too_greedy.patch, * patches/openjdk/6888215-jpeg_memory_leak.patch, * patches/openjdk/6989760-native_warnings.patch, * patches/openjdk/6989774-imageio_compiler_warnings.patch, * patches/openjdk/7013519-integer_overflows.patch, * patches/openjdk/7018912-potential_buffer_overruns_in_jpeg.patch, * patches/openjdk/8005194-scale_memory_leak.patch, * patches/openjdk/8020983-outofmemoryerror_jpegimagewriter.patch: New backports from OpenJDK 7u. diff -r 3c193afea5f3 -r 222321136c48 ChangeLog --- a/ChangeLog Tue Sep 03 18:43:01 2013 +0100 +++ b/ChangeLog Tue Sep 03 20:08:26 2013 +0100 @@ -1,3 +1,26 @@ +2013-08-30 Andrew John Hughes + + * Makefile.am: + (ICEDTEA_PATCHES): Add new patches. + * NEWS: Updated with new patches. + * patches/imageiojpeg_sync.patch: + Bring in changes to imageioJPEG.c made between + the start of OpenJDK 6 and the start of OpenJDK 7's + hg repositories. + * patches/libraries.patch: Updated against patches below. + * patches/openjdk/4893408-jpegreader_byte_gray.patch, + * patches/openjdk/6631559-dont_load_libjpeg_to_register_imageio_plugins.patch, + * patches/openjdk/6791502-invalid_icc_profile.patch, + * patches/openjdk/6793818-jpegimagereader_too_greedy.patch, + * patches/openjdk/6888215-jpeg_memory_leak.patch, + * patches/openjdk/6989760-native_warnings.patch, + * patches/openjdk/6989774-imageio_compiler_warnings.patch, + * patches/openjdk/7013519-integer_overflows.patch, + * patches/openjdk/7018912-potential_buffer_overruns_in_jpeg.patch, + * patches/openjdk/8005194-scale_memory_leak.patch, + * patches/openjdk/8020983-outofmemoryerror_jpegimagewriter.patch: + New backports from OpenJDK 7u. + 2013-08-29 Andrew John Hughes * Makefile.am: diff -r 3c193afea5f3 -r 222321136c48 Makefile.am --- a/Makefile.am Tue Sep 03 18:43:01 2013 +0100 +++ b/Makefile.am Tue Sep 03 20:08:26 2013 +0100 @@ -424,6 +424,16 @@ patches/openjdk/6693253-security_warning.patch \ patches/openjdk/6444769-windowwithwarningtest.patch \ patches/openjdk/6656651-windows_lcd_glyphs.patch \ + patches/openjdk/6791502-invalid_icc_profile.patch \ + patches/openjdk/6793818-jpegimagereader_too_greedy.patch \ + patches/openjdk/6631559-dont_load_libjpeg_to_register_imageio_plugins.patch \ + patches/openjdk/4893408-jpegreader_byte_gray.patch \ + patches/openjdk/6888215-jpeg_memory_leak.patch \ + patches/openjdk/6989774-imageio_compiler_warnings.patch \ + patches/openjdk/7018912-potential_buffer_overruns_in_jpeg.patch \ + patches/openjdk/6989760-native_warnings.patch \ + patches/openjdk/7013519-integer_overflows.patch \ + patches/openjdk/8020983-outofmemoryerror_jpegimagewriter.patch \ patches/notice-safepoints.patch \ patches/parisc-opt.patch \ patches/lucene-crash.patch \ @@ -659,7 +669,9 @@ patches/openjdk/7196533-timezone_bottleneck.patch \ patches/openjdk/6636370-appcontext_simplification.patch \ patches/openjdk/6636331-appcontext_concurrentmodificationexception.patch \ - patches/openjdk/6893617-cnctx_always_uses_default_orb.patch + patches/openjdk/6893617-cnctx_always_uses_default_orb.patch \ + patches/imageiojpeg_sync.patch \ + patches/openjdk/8005194-scale_memory_leak.patch if WITH_RHINO ICEDTEA_PATCHES += \ diff -r 3c193afea5f3 -r 222321136c48 NEWS --- a/NEWS Tue Sep 03 18:43:01 2013 +0100 +++ b/NEWS Tue Sep 03 20:08:26 2013 +0100 @@ -16,6 +16,17 @@ * Backports - S6840152: JVM crashes when heavyweight monitors are used - S7022999: Can't build with FORCE_TIERED=0 + - S4893408: JPEGReader throws IllegalArgException when setting the destination to BYTE_GRAY + - S6631559: Registration of ImageIO plugins should not cause loading of jpeg.dlli and cmm.dll + - S6791502: IIOException "Invalid icc profile" on jpeg after update from JDK5 to JDK6 + - S6793818: JpegImageReader is too greedy creating color profiles + - S6888215: memory leak in jpeg plugin + - S6989760: cmm native compiler warnings + - S6989774: imageio compiler warnings in native code + - S7013519: [parfait] Integer overflows in 2D code + - S7018912: [parfait] potential buffer overruns in imageio jpeg + - S8005194: [parfait] #353 sun/awt/image/jpeg/imageioJPEG.c Memory leak of pointer 'scale' allocated with calloc() + - S8020983, RH976897: OutOfMemoryError caused by non garbage collected JPEGImageWriter Instances * Bug fixes - PR1188: ASM Interpreter and Thumb2 JIT javac miscompile modulo reminder on armel. diff -r 3c193afea5f3 -r 222321136c48 patches/imageiojpeg_sync.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/patches/imageiojpeg_sync.patch Tue Sep 03 20:08:26 2013 +0100 @@ -0,0 +1,217 @@ +diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c +--- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c 2013-08-30 18:50:38.238272213 +0100 ++++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c 2013-08-30 18:57:43.240892673 +0100 +@@ -447,9 +447,6 @@ + pixelBuffer pixelBuf; // Buffer for pixels + + jboolean abortFlag; // Passed down from Java abort method +- +- UINT8 scale[MAX_BANDS][NUM_INPUT_VALUES]; +- int bandSizes[MAX_BANDS]; // For scaling to-from non-8-bit images + } imageIOData, *imageIODataPtr; + + /* +@@ -487,12 +484,6 @@ + + data->abortFlag = JNI_FALSE; + +- for (i = 0; i < MAX_BANDS; i ++) { +- data->bandSizes[i] = 0; +- for (j = 0; j < NUM_INPUT_VALUES; j++) { +- data->scale[i][j] = 0; +- } +- } + return data; + } + +@@ -1978,34 +1969,6 @@ + + (*env)->ReleaseIntArrayElements(env, srcBands, body, JNI_ABORT); + +- bandSize = (*env)->GetIntArrayElements(env, bandSizes, NULL); +- +- for (i = 0; i < numBands; i++) { +- if (bandSize[i] != JPEG_BAND_SIZE) { +- mustScale = TRUE; +- break; +- } +- } +- +- if (mustScale) { +- // Build any scale tables that aren't already OK +- for (i = 0; i < numBands; i++) { +- if (data->bandSizes[i] != bandSize[i]) { +- data->bandSizes[i] = bandSize[i]; +- maxBandValue = (1 << bandSize[i]) - 1; +- halfMaxBandValue = maxBandValue >> 1; +- for (j = 0; j <= maxBandValue; j++) { +- data->scale[i][j] = +- (UINT8)((j*MAX_JPEG_BAND_VALUE +- + halfMaxBandValue)/maxBandValue); +- } +- } +- } +- } +- +- (*env)->ReleaseIntArrayElements(env, bandSizes, +- bandSize, JNI_ABORT); +- + #ifdef DEBUG_IIO_JPEG + printf("---- in reader.read ----\n"); + printf("numBands is %d\n", numBands); +@@ -2028,15 +1991,6 @@ + return data->abortFlag; // We already threw an out of memory exception + } + +- // Allocate a 1-scanline buffer +- if (cinfo->num_components <= 0 || +- cinfo->image_width > (UINT_MAX / (unsigned int)cinfo->num_components)) +- { +- RELEASE_ARRAYS(env, data, src->next_input_byte); +- JNU_ThrowByName(env, "javax/imageio/IIOException", +- "Invalid number of color components"); +- return data->abortFlag; +- } + /* Establish the setjmp return context for sun_jpeg_error_exit to use. */ + jerr = (sun_jpeg_error_ptr) cinfo->err; + +@@ -2154,15 +2108,8 @@ + + // Now mangle it into our buffer + out = data->pixelBuf.buf.bp; +- if (mustScale) { +- for (in = scanLinePtr+sourceXStart*cinfo->num_components; +- in < pixelLimit; +- in += pixelStride) { +- for (i = 0; i < numBands; i++) { +- *out++ = data->scale[i][*(in+bands[i])]; +- } +- } +- } else if (orderedBands && (pixelStride == numBands)) { ++ ++ if (orderedBands && (pixelStride == numBands)) { + // Optimization: The component bands are ordered sequentially, + // so we can simply use memcpy() to copy the intermediate + // scanline buffer into the raster. +@@ -2177,7 +2124,7 @@ + } else { + numBytes = numBands; + for (in = scanLinePtr+sourceXStart*cinfo->output_components; +- in < pixelLimit && ++ in < pixelLimit && + numBytes <= data->pixelBuf.byteBufferLength; + in += pixelStride) { + for (i = 0; i < numBands; i++) { +@@ -2914,9 +2861,10 @@ + jint *scanData; + jint *bandSize; + int maxBandValue, halfMaxBandValue; +- boolean mustScale = FALSE; + imageIODataPtr data = (imageIODataPtr)jlong_to_ptr(ptr); + j_compress_ptr cinfo; ++ UINT8** scale = NULL; ++ + + /* verify the inputs */ + +@@ -2963,24 +2911,32 @@ + + for (i = 0; i < numBands; i++) { + if (bandSize[i] != JPEG_BAND_SIZE) { +- mustScale = TRUE; +- break; +- } +- } ++ if (scale == NULL) { ++ scale = (UINT8**) calloc(numBands, sizeof(UINT8*)); + +- if (mustScale) { +- // Build any scale tables that aren't already OK +- for (i = 0; i < numBands; i++) { +- if (data->bandSizes[i] != bandSize[i]) { +- data->bandSizes[i] = bandSize[i]; +- maxBandValue = (1 << bandSize[i]) - 1; +- halfMaxBandValue = maxBandValue >> 1; +- for (j = 0; j <= maxBandValue; j++) { +- data->scale[i][j] = +- (UINT8)((j*MAX_JPEG_BAND_VALUE +- + halfMaxBandValue)/maxBandValue); ++ if (scale == NULL) { ++ JNU_ThrowByName( env, "java/lang/OutOfMemoryError", ++ "Writing JPEG Stream"); ++ return JNI_FALSE; + } + } ++ ++ maxBandValue = (1 << bandSize[i]) - 1; ++ ++ scale[i] = (UINT8*) malloc((maxBandValue + 1) * sizeof(UINT8)); ++ ++ if (scale[i] == NULL) { ++ JNU_ThrowByName( env, "java/lang/OutOfMemoryError", ++ "Writing JPEG Stream"); ++ return JNI_FALSE; ++ } ++ ++ halfMaxBandValue = maxBandValue >> 1; ++ ++ for (j = 0; j <= maxBandValue; j++) { ++ scale[i][j] = (UINT8) ++ ((j*MAX_JPEG_BAND_VALUE + halfMaxBandValue)/maxBandValue); ++ } + } + } + +@@ -3189,28 +3145,25 @@ + out = scanLinePtr; + pixelLimit = in + ((pixelBufferSize > data->pixelBuf.byteBufferLength) ? + data->pixelBuf.byteBufferLength : pixelBufferSize); +- if (mustScale) { +- for (; (in < pixelLimit) && (out < scanLineLimit); in += pixelStride) { +- for (i = 0; i < numBands; i++) { +- *out++ = data->scale[i][*(in+i)]; ++ for (; (in < pixelLimit) && (out < scanLineLimit); in += pixelStride) { ++ for (i = 0; i < numBands; i++) { ++ if (scale !=NULL && scale[i] != NULL) { ++ *out++ = scale[i][*(in+i)]; + #ifdef DEBUG_IIO_JPEG + if (in == data->pixelBuf.buf.bp){ // Just the first pixel + printf("in %d -> out %d, ", *(in+i), *(out-i-1)); + } + #endif +- } ++ + #ifdef DEBUG_IIO_JPEG + if (in == data->pixelBuf.buf.bp){ // Just the first pixel + printf("\n"); + } + #endif +- } +- } else { +- for (; (in < pixelLimit) && (out < scanLineLimit); in += pixelStride) { +- for (i = 0; i < numBands; i++) { ++ } else { + *out++ = *(in+i); + } +- } ++ } + } + // write it out + jpegwritescanlines(cinfo, (JSAMPARRAY)&scanLinePtr, 1); +@@ -3226,6 +3179,16 @@ + } else { + jpegabort((j_common_ptr)cinfo); + } ++ ++ if (scale != NULL) { ++ for (i = 0; i < numBands; i++) { ++ if (scale[i] != NULL) { ++ free(scale[i]); ++ } ++ } ++ free(scale); ++ } ++ + free(scanLinePtr); + RELEASE_ARRAYS(env, data, NULL); + return data->abortFlag; diff -r 3c193afea5f3 -r 222321136c48 patches/libraries.patch --- a/patches/libraries.patch Tue Sep 03 18:43:01 2013 +0100 +++ b/patches/libraries.patch Tue Sep 03 20:08:26 2013 +0100 @@ -1,6 +1,6 @@ diff -Nru openjdk.orig/jdk/make/com/sun/java/pack/Makefile openjdk/jdk/make/com/sun/java/pack/Makefile --- openjdk.orig/jdk/make/com/sun/java/pack/Makefile 2011-11-14 22:11:39.000000000 +0000 -+++ openjdk/jdk/make/com/sun/java/pack/Makefile 2013-04-16 15:14:38.655921054 +0100 ++++ openjdk/jdk/make/com/sun/java/pack/Makefile 2013-09-03 19:16:25.070981473 +0100 @@ -64,23 +64,21 @@ ZIPOBJDIR = $(OUTPUTDIR)/tmp/sun/java.util.zip/zip/$(OBJDIRNAME) @@ -55,7 +55,7 @@ endif #PLATFORM diff -Nru openjdk.orig/jdk/make/common/Program.gmk openjdk/jdk/make/common/Program.gmk --- openjdk.orig/jdk/make/common/Program.gmk 2011-11-14 22:11:39.000000000 +0000 -+++ openjdk/jdk/make/common/Program.gmk 2013-04-16 15:14:54.104167811 +0100 ++++ openjdk/jdk/make/common/Program.gmk 2013-09-03 19:16:25.070981473 +0100 @@ -85,7 +85,7 @@ endif endif @@ -75,7 +75,7 @@ VERSION_DEFINES += -DFULL_VERSION='"$(FULL_VERSION)"' diff -Nru openjdk.orig/jdk/make/java/jli/Makefile openjdk/jdk/make/java/jli/Makefile --- openjdk.orig/jdk/make/java/jli/Makefile 2011-11-14 22:11:40.000000000 +0000 -+++ openjdk/jdk/make/java/jli/Makefile 2013-04-16 15:14:38.659921118 +0100 ++++ openjdk/jdk/make/java/jli/Makefile 2013-09-03 19:16:25.070981473 +0100 @@ -44,8 +44,6 @@ include $(BUILDDIR)/common/Defs.gmk @@ -127,7 +127,7 @@ diff -Nru openjdk.orig/jdk/make/java/zip/FILES_c.gmk openjdk/jdk/make/java/zip/FILES_c.gmk --- openjdk.orig/jdk/make/java/zip/FILES_c.gmk 2011-11-14 22:11:40.000000000 +0000 -+++ openjdk/jdk/make/java/zip/FILES_c.gmk 2013-04-16 15:14:38.631920670 +0100 ++++ openjdk/jdk/make/java/zip/FILES_c.gmk 2013-09-03 19:16:25.070981473 +0100 @@ -30,15 +30,4 @@ Inflater.c \ ZipFile.c \ @@ -146,7 +146,7 @@ zip_util.c diff -Nru openjdk.orig/jdk/make/java/zip/Makefile openjdk/jdk/make/java/zip/Makefile --- openjdk.orig/jdk/make/java/zip/Makefile 2011-11-14 22:11:40.000000000 +0000 -+++ openjdk/jdk/make/java/zip/Makefile 2013-04-16 15:14:38.631920670 +0100 ++++ openjdk/jdk/make/java/zip/Makefile 2013-09-03 19:16:25.070981473 +0100 @@ -30,8 +30,6 @@ PRODUCT = sun include $(BUILDDIR)/common/Defs.gmk @@ -176,7 +176,7 @@ +OTHER_LDLIBS = $(JVMLIB) -lz diff -Nru openjdk.orig/jdk/make/sun/jpeg/FILES_c.gmk openjdk/jdk/make/sun/jpeg/FILES_c.gmk --- openjdk.orig/jdk/make/sun/jpeg/FILES_c.gmk 2011-11-14 22:11:41.000000000 +0000 -+++ openjdk/jdk/make/sun/jpeg/FILES_c.gmk 2013-04-16 15:14:38.635920734 +0100 ++++ openjdk/jdk/make/sun/jpeg/FILES_c.gmk 2013-09-03 19:16:25.070981473 +0100 @@ -25,51 +25,7 @@ FILES_c = \ @@ -231,9 +231,9 @@ ifndef OPENJDK FILES_c += \ diff -Nru openjdk.orig/jdk/make/sun/jpeg/Makefile openjdk/jdk/make/sun/jpeg/Makefile ---- openjdk.orig/jdk/make/sun/jpeg/Makefile 2011-11-14 22:11:41.000000000 +0000 -+++ openjdk/jdk/make/sun/jpeg/Makefile 2013-04-16 15:14:38.619920479 +0100 -@@ -68,6 +68,8 @@ +--- openjdk.orig/jdk/make/sun/jpeg/Makefile 2013-09-03 19:02:34.690068319 +0100 ++++ openjdk/jdk/make/sun/jpeg/Makefile 2013-09-03 19:16:25.070981473 +0100 +@@ -81,6 +81,8 @@ include $(BUILDDIR)/common/Mapfile-vers.gmk include $(BUILDDIR)/common/Library.gmk @@ -244,7 +244,7 @@ # diff -Nru openjdk.orig/jdk/make/sun/splashscreen/FILES_c.gmk openjdk/jdk/make/sun/splashscreen/FILES_c.gmk --- openjdk.orig/jdk/make/sun/splashscreen/FILES_c.gmk 2011-11-14 22:11:41.000000000 +0000 -+++ openjdk/jdk/make/sun/splashscreen/FILES_c.gmk 2013-04-16 15:14:38.635920734 +0100 ++++ openjdk/jdk/make/sun/splashscreen/FILES_c.gmk 2013-09-03 19:16:25.070981473 +0100 @@ -30,81 +30,5 @@ splashscreen_impl.c \ splashscreen_jpeg.c \ @@ -330,7 +330,7 @@ diff -Nru openjdk.orig/jdk/make/sun/splashscreen/Makefile openjdk/jdk/make/sun/splashscreen/Makefile --- openjdk.orig/jdk/make/sun/splashscreen/Makefile 2011-11-14 22:11:41.000000000 +0000 -+++ openjdk/jdk/make/sun/splashscreen/Makefile 2013-04-16 15:14:38.635920734 +0100 ++++ openjdk/jdk/make/sun/splashscreen/Makefile 2013-09-03 19:16:25.070981473 +0100 @@ -59,12 +59,12 @@ # C Flags # @@ -362,8 +362,8 @@ ifeq ($(PLATFORM), linux) ifeq ($(ARCH_DATA_MODEL), 64) diff -Nru openjdk.orig/jdk/src/share/native/com/sun/java/util/jar/pack/defines.h openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/defines.h ---- openjdk.orig/jdk/src/share/native/com/sun/java/util/jar/pack/defines.h 2013-04-16 15:13:38.614962261 +0100 -+++ openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/defines.h 2013-04-16 15:16:29.385690279 +0100 +--- openjdk.orig/jdk/src/share/native/com/sun/java/util/jar/pack/defines.h 2013-09-03 19:02:28.593973514 +0100 ++++ openjdk/jdk/src/share/native/com/sun/java/util/jar/pack/defines.h 2013-09-03 19:16:25.070981473 +0100 @@ -89,11 +89,7 @@ // bytes and byte arrays @@ -378,7 +378,7 @@ typedef DWORDLONG julong; diff -Nru openjdk.orig/jdk/src/share/native/java/util/zip/Adler32.c openjdk/jdk/src/share/native/java/util/zip/Adler32.c --- openjdk.orig/jdk/src/share/native/java/util/zip/Adler32.c 2011-11-14 22:12:11.000000000 +0000 -+++ openjdk/jdk/src/share/native/java/util/zip/Adler32.c 2013-04-16 15:14:38.631920670 +0100 ++++ openjdk/jdk/src/share/native/java/util/zip/Adler32.c 2013-09-03 19:16:25.070981473 +0100 @@ -29,7 +29,7 @@ #include "jni.h" @@ -390,7 +390,7 @@ diff -Nru openjdk.orig/jdk/src/share/native/java/util/zip/CRC32.c openjdk/jdk/src/share/native/java/util/zip/CRC32.c --- openjdk.orig/jdk/src/share/native/java/util/zip/CRC32.c 2011-11-14 22:12:11.000000000 +0000 -+++ openjdk/jdk/src/share/native/java/util/zip/CRC32.c 2013-04-16 15:14:38.631920670 +0100 ++++ openjdk/jdk/src/share/native/java/util/zip/CRC32.c 2013-09-03 19:16:25.070981473 +0100 @@ -29,7 +29,7 @@ #include "jni.h" @@ -402,7 +402,7 @@ diff -Nru openjdk.orig/jdk/src/share/native/java/util/zip/Deflater.c openjdk/jdk/src/share/native/java/util/zip/Deflater.c --- openjdk.orig/jdk/src/share/native/java/util/zip/Deflater.c 2011-11-14 22:12:11.000000000 +0000 -+++ openjdk/jdk/src/share/native/java/util/zip/Deflater.c 2013-04-16 15:14:38.631920670 +0100 ++++ openjdk/jdk/src/share/native/java/util/zip/Deflater.c 2013-09-03 19:16:25.070981473 +0100 @@ -32,7 +32,7 @@ #include "jlong.h" #include "jni.h" @@ -414,7 +414,7 @@ diff -Nru openjdk.orig/jdk/src/share/native/java/util/zip/Inflater.c openjdk/jdk/src/share/native/java/util/zip/Inflater.c --- openjdk.orig/jdk/src/share/native/java/util/zip/Inflater.c 2011-11-14 22:12:11.000000000 +0000 -+++ openjdk/jdk/src/share/native/java/util/zip/Inflater.c 2013-04-16 15:14:38.635920734 +0100 ++++ openjdk/jdk/src/share/native/java/util/zip/Inflater.c 2013-09-03 19:16:25.070981473 +0100 @@ -35,7 +35,7 @@ #include "jni.h" #include "jvm.h" @@ -425,8 +425,8 @@ #define ThrowDataFormatException(env, msg) \ diff -Nru openjdk.orig/jdk/src/share/native/java/util/zip/zip_util.c openjdk/jdk/src/share/native/java/util/zip/zip_util.c ---- openjdk.orig/jdk/src/share/native/java/util/zip/zip_util.c 2013-04-16 15:13:37.094937993 +0100 -+++ openjdk/jdk/src/share/native/java/util/zip/zip_util.c 2013-04-16 15:14:38.635920734 +0100 +--- openjdk.orig/jdk/src/share/native/java/util/zip/zip_util.c 2013-09-03 19:02:31.974026079 +0100 ++++ openjdk/jdk/src/share/native/java/util/zip/zip_util.c 2013-09-03 19:16:25.070981473 +0100 @@ -44,7 +44,8 @@ #include "io_util.h" #include "io_util_md.h" @@ -438,8 +438,8 @@ /* USE_MMAP means mmap the CEN & ENDHDR part of the zip file. */ #ifdef USE_MMAP diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c ---- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c 2013-04-16 15:13:40.594993873 +0100 -+++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c 2013-04-16 15:16:08.277352923 +0100 +--- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c 2013-09-03 19:02:34.766069501 +0100 ++++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c 2013-09-03 19:20:11.750506169 +0100 @@ -52,7 +52,9 @@ /* headers from the JPEG library */ @@ -514,7 +514,7 @@ /* * Defined in jpegdecoder.c. Copy code from there if and * when that disappears. */ -@@ -619,7 +677,7 @@ +@@ -627,7 +685,7 @@ return; } @@ -523,7 +523,7 @@ } -@@ -644,7 +702,7 @@ +@@ -652,7 +710,7 @@ return; } @@ -532,7 +532,7 @@ } -@@ -662,7 +720,7 @@ +@@ -670,7 +728,7 @@ free(cinfo->dest); cinfo->dest = NULL; } @@ -541,7 +541,7 @@ free(info); } } -@@ -702,14 +760,14 @@ +@@ -710,14 +768,14 @@ decomp = (j_decompress_ptr) cinfo; if (decomp->quant_tbl_ptrs[i] == NULL) { decomp->quant_tbl_ptrs[i] = @@ -558,7 +558,7 @@ } quant_ptr = comp->quant_tbl_ptrs[i]; } -@@ -800,14 +858,14 @@ +@@ -808,14 +866,14 @@ decomp = (j_decompress_ptr) cinfo; if (decomp->dc_huff_tbl_ptrs[i] == NULL) { decomp->dc_huff_tbl_ptrs[i] = @@ -575,7 +575,7 @@ } huff_ptr = comp->dc_huff_tbl_ptrs[i]; } -@@ -825,14 +883,14 @@ +@@ -833,14 +891,14 @@ decomp = (j_decompress_ptr) cinfo; if (decomp->ac_huff_tbl_ptrs[i] == NULL) { decomp->ac_huff_tbl_ptrs[i] = @@ -592,7 +592,7 @@ } huff_ptr = comp->ac_huff_tbl_ptrs[i]; } -@@ -1374,6 +1432,8 @@ +@@ -1411,6 +1469,8 @@ jclass qTableClass, jclass huffClass) { @@ -601,7 +601,7 @@ JPEGImageReader_readInputDataID = (*env)->GetMethodID(env, cls, "readInputData", -@@ -1458,7 +1518,7 @@ +@@ -1496,7 +1556,7 @@ } /* We set up the normal JPEG error routines, then override error_exit. */ @@ -610,7 +610,7 @@ jerr->pub.error_exit = sun_jpeg_error_exit; /* We need to setup our own print routines */ jerr->pub.output_message = sun_jpeg_output_message; -@@ -1475,11 +1535,11 @@ +@@ -1513,11 +1573,11 @@ } /* Perform library initialization */ @@ -624,7 +624,7 @@ /* * Now set up our source. -@@ -1497,7 +1557,7 @@ +@@ -1536,7 +1596,7 @@ cinfo->src->init_source = imageio_init_source; cinfo->src->fill_input_buffer = imageio_fill_input_buffer; cinfo->src->skip_input_data = imageio_skip_input_data; @@ -633,7 +633,7 @@ cinfo->src->term_source = imageio_term_source; /* set up the association to persist for future calls */ -@@ -1614,7 +1674,7 @@ +@@ -1655,7 +1715,7 @@ src->bytes_in_buffer = 0; } @@ -642,16 +642,16 @@ if (ret == JPEG_HEADER_TABLES_ONLY) { retval = JNI_TRUE; -@@ -1735,7 +1795,7 @@ +@@ -1784,7 +1844,7 @@ cinfo->num_components, - read_icc_profile(env, cinfo)); + profileData); if (reset) { - jpeg_abort_decompress(cinfo); + jpegabortdecompress(cinfo); } } -@@ -1975,7 +2035,7 @@ +@@ -2016,7 +2076,7 @@ TRUE); } @@ -660,16 +660,16 @@ if (progressive) { cinfo->buffered_image = TRUE; cinfo->input_scan_number = minProgressivePass+1; // Java count from 0 -@@ -1987,7 +2047,7 @@ +@@ -2028,7 +2088,7 @@ data->streamBuf.suspendable = FALSE; - jpeg_start_decompress(cinfo); + jpegstartdecompress(cinfo); - // loop over progressive passes - done = FALSE; -@@ -1995,7 +2055,7 @@ + if (numBands != cinfo->output_components) { + JNU_ThrowByName(env, "javax/imageio/IIOException", +@@ -2060,7 +2120,7 @@ if (progressive) { // initialize the next pass. Note that this skips up to // the first interesting pass. @@ -678,7 +678,7 @@ if (wantUpdates) { (*env)->CallVoidMethod(env, this, JPEGImageReader_passStartedID, -@@ -2011,7 +2071,7 @@ +@@ -2076,7 +2136,7 @@ // Skip until the first interesting line while ((data->abortFlag == JNI_FALSE) && ((jint)cinfo->output_scanline < sourceYStart)) { @@ -687,7 +687,7 @@ } scanlineLimit = sourceYStart+sourceHeight; -@@ -2024,7 +2084,7 @@ +@@ -2089,7 +2149,7 @@ while ((data->abortFlag == JNI_FALSE) && ((jint)cinfo->output_scanline < scanlineLimit)) { @@ -696,7 +696,7 @@ // Now mangle it into our buffer out = data->pixelBuf.buf.bp; -@@ -2086,13 +2146,13 @@ +@@ -2151,13 +2211,13 @@ skipLines = linesLeft; } for(i = 0; i < skipLines; i++) { @@ -713,7 +713,7 @@ || (cinfo->input_scan_number > maxProgressivePass)) { done = TRUE; } -@@ -2112,9 +2172,9 @@ +@@ -2177,9 +2237,9 @@ if (cinfo->output_scanline == cinfo->output_height) { // if ((cinfo->output_scanline == cinfo->output_height) && //(jpeg_input_complete(cinfo))) { // We read the whole file @@ -725,7 +725,7 @@ } free(scanLinePtr); -@@ -2160,7 +2220,7 @@ +@@ -2225,7 +2285,7 @@ cinfo = (j_decompress_ptr) data->jpegObj; @@ -734,7 +734,7 @@ } -@@ -2366,6 +2426,150 @@ +@@ -2439,6 +2499,150 @@ /********************** end of destination manager ************/ @@ -885,7 +885,7 @@ /********************** Writer JNI calls **********************/ -@@ -2375,6 +2579,8 @@ +@@ -2448,6 +2652,8 @@ jclass cls, jclass qTableClass, jclass huffClass) { @@ -894,7 +894,7 @@ JPEGImageWriter_writeOutputDataID = (*env)->GetMethodID(env, cls, -@@ -2449,7 +2655,7 @@ +@@ -2522,7 +2728,7 @@ } /* We set up the normal JPEG error routines, then override error_exit. */ @@ -903,7 +903,7 @@ jerr->pub.error_exit = sun_jpeg_error_exit; /* We need to setup our own print routines */ jerr->pub.output_message = sun_jpeg_output_message; -@@ -2466,7 +2672,7 @@ +@@ -2539,7 +2745,7 @@ } /* Perform library initialization */ @@ -912,7 +912,7 @@ /* Now set up the destination */ dest = malloc(sizeof(struct jpeg_destination_mgr)); -@@ -2574,7 +2780,7 @@ +@@ -2645,7 +2851,7 @@ return; } @@ -921,7 +921,7 @@ data->streamBuf.suspendable = FALSE; if (qtables != NULL) { -@@ -2589,7 +2795,7 @@ +@@ -2660,7 +2866,7 @@ DCHuffmanTables, ACHuffmanTables, TRUE); } @@ -930,7 +930,7 @@ RELEASE_ARRAYS(env, data, NULL); } -@@ -2753,9 +2959,9 @@ +@@ -2834,9 +3040,9 @@ cinfo->input_components = numBands; cinfo->in_color_space = inCs; @@ -942,7 +942,7 @@ cinfo->optimize_coding = optimize; -@@ -2792,7 +2998,7 @@ +@@ -2873,7 +3079,7 @@ (*env)->ReleaseIntArrayElements(env, QtableSelectors, qsels, JNI_ABORT); @@ -951,7 +951,7 @@ qlen = setQTables(env, (j_common_ptr) cinfo, qtables, writeDQT); -@@ -2817,7 +3023,7 @@ +@@ -2898,7 +3104,7 @@ if (progressive) { if (numScans == 0) { // then use default scans @@ -960,7 +960,7 @@ } else { cinfo->num_scans = numScans; // Copy the scanInfo to a local array -@@ -2859,7 +3065,7 @@ +@@ -2940,7 +3146,7 @@ #endif // start the compressor; tables must already be set @@ -969,7 +969,7 @@ if (haveMetadata) { // Flush the buffer -@@ -2925,7 +3131,7 @@ +@@ -3006,7 +3212,7 @@ } } // write it out @@ -978,7 +978,7 @@ targetLine += stepY; } -@@ -2934,9 +3140,9 @@ +@@ -3015,9 +3221,9 @@ * so use jpeg_abort instead of jpeg_finish_compress. */ if (cinfo->next_scanline == cinfo->image_height) { @@ -12378,7 +12378,7 @@ - } -} diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jdmarker.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/jdmarker.c ---- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jdmarker.c 2011-11-14 22:12:12.000000000 +0000 +--- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jdmarker.c 2013-09-03 19:02:34.690068319 +0100 +++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jdmarker.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,1384 +0,0 @@ -/* @@ -13708,14 +13708,14 @@ - unsigned int length_limit) -{ - my_marker_ptr marker = (my_marker_ptr) cinfo->marker; -- long maxlength; +- size_t maxlength; - jpeg_marker_parser_method processor; - - /* Length limit mustn't be larger than what we can allocate - * (should only be a concern in a 16-bit environment). - */ - maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct); -- if (((long) length_limit) > maxlength) +- if (length_limit > maxlength) - length_limit = (unsigned int) maxlength; - - /* Choose processor routine to use. @@ -19152,9 +19152,9 @@ -#define JFWRITE(file,buf,sizeofbuf) \ - ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file))) diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jmemmgr.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/jmemmgr.c ---- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jmemmgr.c 2011-11-14 22:12:12.000000000 +0000 +--- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jmemmgr.c 2013-09-03 19:02:34.690068319 +0100 +++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jmemmgr.c 1970-01-01 01:00:00.000000000 +0100 -@@ -1,1122 +0,0 @@ +@@ -1,1124 +0,0 @@ -/* - * reserved comment block - * DO NOT REMOVE OR ALTER! @@ -19290,7 +19290,7 @@ - jvirt_barray_ptr virt_barray_list; - - /* This counts total space obtained from jpeg_get_small/large */ -- long total_space_allocated; +- size_t total_space_allocated; - - /* alloc_sarray and alloc_barray set this value for use by virtual - * array routines. @@ -19745,8 +19745,8 @@ -/* Allocate the in-memory buffers for any unrealized virtual arrays */ -{ - my_mem_ptr mem = (my_mem_ptr) cinfo->mem; -- long space_per_minheight, maximum_space, avail_mem; -- long minheights, max_minheights; +- size_t space_per_minheight, maximum_space, avail_mem; +- size_t minheights, max_minheights; - jvirt_sarray_ptr sptr; - jvirt_barray_ptr bptr; - @@ -20189,7 +20189,7 @@ -jinit_memory_mgr (j_common_ptr cinfo) -{ - my_mem_ptr mem; -- long max_to_use; +- size_t max_to_use; - int pool; - size_t test_mac; - @@ -20266,8 +20266,10 @@ - - if ((memenv = getenv("JPEGMEM")) != NULL) { - char ch = 'x'; -- -- if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) { +- unsigned int mem_max = 0u; +- +- if (sscanf(memenv, "%u%c", &mem_max, &ch) > 0) { +- max_to_use = (size_t)mem_max; - if (ch == 'm' || ch == 'M') - max_to_use *= 1000L; - mem->pub.max_memory_to_use = max_to_use * 1000L; @@ -20278,7 +20280,7 @@ - -} diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jmemnobs.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/jmemnobs.c ---- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jmemnobs.c 2011-11-14 22:12:12.000000000 +0000 +--- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jmemnobs.c 2013-09-03 19:02:34.694068380 +0100 +++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jmemnobs.c 1970-01-01 01:00:00.000000000 +0100 @@ -1,113 +0,0 @@ -/* @@ -20356,9 +20358,9 @@ - * Here we always say, "we got all you want bud!" - */ - --GLOBAL(long) --jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, -- long max_bytes_needed, long already_allocated) +-GLOBAL(size_t) +-jpeg_mem_available (j_common_ptr cinfo, size_t min_bytes_needed, +- size_t max_bytes_needed, size_t already_allocated) -{ - return max_bytes_needed; -} @@ -20383,7 +20385,7 @@ - * cleanup required. Here, there isn't any. - */ - --GLOBAL(long) +-GLOBAL(size_t) -jpeg_mem_init (j_common_ptr cinfo) -{ - return 0; /* just set max_memory_to_use to 0 */ @@ -20395,7 +20397,7 @@ - /* no work */ -} diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jmemsys.h openjdk/jdk/src/share/native/sun/awt/image/jpeg/jmemsys.h ---- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jmemsys.h 2011-11-14 22:12:12.000000000 +0000 +--- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jmemsys.h 2013-09-03 19:02:34.694068380 +0100 +++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jmemsys.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,202 +0,0 @@ -/* @@ -20504,10 +20506,10 @@ - * Conversely, zero may be returned to always use the minimum amount of memory. - */ - --EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo, -- long min_bytes_needed, -- long max_bytes_needed, -- long already_allocated)); +-EXTERN(size_t) jpeg_mem_available JPP((j_common_ptr cinfo, +- size_t min_bytes_needed, +- size_t max_bytes_needed, +- size_t already_allocated)); - - -/* @@ -20598,7 +20600,7 @@ - * all opened backing-store objects have been closed. - */ - --EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo)); +-EXTERN(size_t) jpeg_mem_init JPP((j_common_ptr cinfo)); -EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo)); diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jmorecfg.h openjdk/jdk/src/share/native/sun/awt/image/jpeg/jmorecfg.h --- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jmorecfg.h 2011-11-14 22:12:12.000000000 +0000 @@ -20980,8 +20982,8 @@ - -#endif /* JPEG_INTERNAL_OPTIONS */ diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c ---- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c 2011-11-14 22:12:12.000000000 +0000 -+++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c 2013-04-16 15:14:38.659921118 +0100 +--- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c 2013-09-03 19:02:34.694068380 +0100 ++++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c 2013-09-03 19:16:25.090981786 +0100 @@ -45,7 +45,9 @@ #undef boolean #undef FAR @@ -21644,7 +21646,7 @@ -#endif -#endif /* INCOMPLETE_TYPES_BROKEN */ diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jpeglib.h openjdk/jdk/src/share/native/sun/awt/image/jpeg/jpeglib.h ---- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jpeglib.h 2011-11-14 22:12:12.000000000 +0000 +--- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jpeglib.h 2013-09-03 19:02:34.694068380 +0100 +++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jpeglib.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,1100 +0,0 @@ -/* @@ -22449,10 +22451,10 @@ - * used for virtual-array buffers.) May be changed by outer application - * after creating the JPEG object. - */ -- long max_memory_to_use; +- size_t max_memory_to_use; - - /* Maximum allocation request accepted by alloc_large. */ -- long max_alloc_chunk; +- size_t max_alloc_chunk; -}; - - @@ -25529,7 +25531,7 @@ -Please send bug reports, offers of help, etc. to jpeg-info@uunet.uu.net. diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/splashscreen/splashscreen_gif.c openjdk/jdk/src/share/native/sun/awt/splashscreen/splashscreen_gif.c --- openjdk.orig/jdk/src/share/native/sun/awt/splashscreen/splashscreen_gif.c 2011-11-14 22:12:12.000000000 +0000 -+++ openjdk/jdk/src/share/native/sun/awt/splashscreen/splashscreen_gif.c 2013-04-16 15:14:38.631920670 +0100 ++++ openjdk/jdk/src/share/native/sun/awt/splashscreen/splashscreen_gif.c 2013-09-03 19:16:25.090981786 +0100 @@ -26,7 +26,7 @@ #include "splashscreen_impl.h" #include "splashscreen_gfx.h" @@ -25540,8 +25542,8 @@ #define GIF_TRANSPARENT 0x01 #define GIF_USER_INPUT 0x02 diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/splashscreen/splashscreen_jpeg.c openjdk/jdk/src/share/native/sun/awt/splashscreen/splashscreen_jpeg.c ---- openjdk.orig/jdk/src/share/native/sun/awt/splashscreen/splashscreen_jpeg.c 2013-04-16 15:13:38.594961941 +0100 -+++ openjdk/jdk/src/share/native/sun/awt/splashscreen/splashscreen_jpeg.c 2013-04-16 15:14:38.655921054 +0100 +--- openjdk.orig/jdk/src/share/native/sun/awt/splashscreen/splashscreen_jpeg.c 2013-09-03 19:02:28.549972830 +0100 ++++ openjdk/jdk/src/share/native/sun/awt/splashscreen/splashscreen_jpeg.c 2013-09-03 19:16:25.090981786 +0100 @@ -25,9 +25,8 @@ #include "splashscreen_impl.h" @@ -25573,7 +25575,7 @@ src = (stream_src_ptr) cinfo->src; diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/splashscreen/splashscreen_png.c openjdk/jdk/src/share/native/sun/awt/splashscreen/splashscreen_png.c --- openjdk.orig/jdk/src/share/native/sun/awt/splashscreen/splashscreen_png.c 2011-11-14 22:12:12.000000000 +0000 -+++ openjdk/jdk/src/share/native/sun/awt/splashscreen/splashscreen_png.c 2013-04-16 15:14:38.631920670 +0100 ++++ openjdk/jdk/src/share/native/sun/awt/splashscreen/splashscreen_png.c 2013-09-03 19:16:25.090981786 +0100 @@ -25,7 +25,7 @@ #include "splashscreen_impl.h" diff -r 3c193afea5f3 -r 222321136c48 patches/openjdk/4893408-jpegreader_byte_gray.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/patches/openjdk/4893408-jpegreader_byte_gray.patch Tue Sep 03 20:08:26 2013 +0100 @@ -0,0 +1,747 @@ +diff -Nru openjdk.orig/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java +--- openjdk.orig/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java 2013-08-30 16:19:36.256416002 +0100 ++++ openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java 2013-08-30 16:20:25.453181852 +0100 +@@ -53,6 +53,7 @@ + import java.util.List; + import java.util.Iterator; + import java.util.ArrayList; ++import java.util.NoSuchElementException; + + import sun.java2d.Disposer; + import sun.java2d.DisposerRecord; +@@ -215,51 +216,6 @@ + /** The DisposerRecord that handles the actual disposal of this reader. */ + private DisposerRecord disposerRecord; + +- /** +- * Maintain an array of the default image types corresponding to the +- * various supported IJG colorspace codes. +- */ +- private static final ImageTypeSpecifier [] defaultTypes = +- new ImageTypeSpecifier [JPEG.NUM_JCS_CODES]; +- +- static { +- defaultTypes[JPEG.JCS_GRAYSCALE] = +- ImageTypeSpecifier.createFromBufferedImageType +- (BufferedImage.TYPE_BYTE_GRAY); +- defaultTypes[JPEG.JCS_RGB] = +- ImageTypeSpecifier.createInterleaved +- (JPEG.JCS.sRGB, +- JPEG.bOffsRGB, +- DataBuffer.TYPE_BYTE, +- false, +- false); +- defaultTypes[JPEG.JCS_RGBA] = +- ImageTypeSpecifier.createPacked +- (JPEG.JCS.sRGB, +- 0xff000000, +- 0x00ff0000, +- 0x0000ff00, +- 0x000000ff, +- DataBuffer.TYPE_INT, +- false); +- if (JPEG.JCS.YCC != null) { +- defaultTypes[JPEG.JCS_YCC] = +- ImageTypeSpecifier.createInterleaved +- (JPEG.JCS.YCC, +- JPEG.bandOffsets[2], +- DataBuffer.TYPE_BYTE, +- false, +- false); +- defaultTypes[JPEG.JCS_YCCA] = +- ImageTypeSpecifier.createInterleaved +- (JPEG.JCS.YCC, +- JPEG.bandOffsets[3], +- DataBuffer.TYPE_BYTE, +- true, +- false); +- } +- } +- + /** Sets up static C structures. */ + private static native void initReaderIDs(Class iisClass, + Class qTableClass, +@@ -767,11 +723,11 @@ + * Return an ImageTypeSpecifier corresponding to the given + * color space code, or null if the color space is unsupported. + */ +- private ImageTypeSpecifier getImageType(int code) { +- ImageTypeSpecifier ret = null; ++ private ImageTypeProducer getImageType(int code) { ++ ImageTypeProducer ret = null; + + if ((code > 0) && (code < JPEG.NUM_JCS_CODES)) { +- ret = defaultTypes[code]; ++ ret = ImageTypeProducer.getTypeProducer(code); + } + return ret; + } +@@ -787,7 +743,7 @@ + } + + // Returns null if it can't be represented +- return getImageType(colorSpaceCode); ++ return getImageType(colorSpaceCode).getType(); + } finally { + clearThreadLock(); + } +@@ -822,13 +778,13 @@ + + // Get the raw ITS, if there is one. Note that this + // won't always be the same as the default. +- ImageTypeSpecifier raw = getImageType(colorSpaceCode); ++ ImageTypeProducer raw = getImageType(colorSpaceCode); + + // Given the encoded colorspace, build a list of ITS's + // representing outputs you could handle starting + // with the default. + +- ArrayList list = new ArrayList(1); ++ ArrayList list = new ArrayList(1); + + switch (colorSpaceCode) { + case JPEG.JCS_GRAYSCALE: +@@ -838,9 +794,7 @@ + case JPEG.JCS_RGB: + list.add(raw); + list.add(getImageType(JPEG.JCS_GRAYSCALE)); +- if (JPEG.JCS.YCC != null) { +- list.add(getImageType(JPEG.JCS_YCC)); +- } ++ list.add(getImageType(JPEG.JCS_YCC)); + break; + case JPEG.JCS_RGBA: + list.add(raw); +@@ -865,19 +819,21 @@ + list.add(getImageType(JPEG.JCS_RGB)); + + if (iccCS != null) { +- list.add(ImageTypeSpecifier.createInterleaved ++ list.add(new ImageTypeProducer() { ++ protected ImageTypeSpecifier produce() { ++ return ImageTypeSpecifier.createInterleaved + (iccCS, + JPEG.bOffsRGB, // Assume it's for RGB + DataBuffer.TYPE_BYTE, + false, +- false)); ++ false); ++ } ++ }); + + } + + list.add(getImageType(JPEG.JCS_GRAYSCALE)); +- if (JPEG.JCS.YCC != null) { // Might be null if PYCC.pf not installed +- list.add(getImageType(JPEG.JCS_YCC)); +- } ++ list.add(getImageType(JPEG.JCS_YCC)); + break; + case JPEG.JCS_YCbCrA: // Default is to convert to RGBA + // As there is no YCbCr ColorSpace, we can't support +@@ -886,7 +842,7 @@ + break; + } + +- return list.iterator(); ++ return new ImageTypeIterator(list.iterator()); + } + + /** +@@ -936,6 +892,10 @@ + if (csType == ColorSpace.TYPE_RGB) { // We want RGB + // IJG can do this for us more efficiently + setOutColorSpace(structPointer, JPEG.JCS_RGB); ++ // Update java state according to changes ++ // in the native part of decoder. ++ outColorSpaceCode = JPEG.JCS_RGB; ++ numComponents = 3; + } else if (csType != ColorSpace.TYPE_GRAY) { + throw new IIOException("Incompatible color conversion"); + } +@@ -945,6 +905,10 @@ + if (colorSpaceCode == JPEG.JCS_YCbCr) { + // If the jpeg space is YCbCr, IJG can do it + setOutColorSpace(structPointer, JPEG.JCS_GRAYSCALE); ++ // Update java state according to changes ++ // in the native part of decoder. ++ outColorSpaceCode = JPEG.JCS_GRAYSCALE; ++ numComponents = 1; + } + } else if ((iccCS != null) && + (cm.getNumComponents() == numComponents) && +@@ -970,20 +934,26 @@ + } + break; + case JPEG.JCS_YCC: +- if (JPEG.JCS.YCC == null) { // We can't do YCC at all +- throw new IIOException("Incompatible color conversion"); +- } +- if ((cs != JPEG.JCS.YCC) && +- (cm.getNumComponents() == numComponents)) { +- convert = new ColorConvertOp(JPEG.JCS.YCC, cs, null); ++ { ++ ColorSpace YCC = JPEG.JCS.getYCC(); ++ if (YCC == null) { // We can't do YCC at all ++ throw new IIOException("Incompatible color conversion"); ++ } ++ if ((cs != YCC) && ++ (cm.getNumComponents() == numComponents)) { ++ convert = new ColorConvertOp(YCC, cs, null); ++ } + } + break; + case JPEG.JCS_YCCA: +- // No conversions available; image must be YCCA +- if ((JPEG.JCS.YCC == null) || // We can't do YCC at all +- (cs != JPEG.JCS.YCC) || +- (cm.getNumComponents() != numComponents)) { +- throw new IIOException("Incompatible color conversion"); ++ { ++ ColorSpace YCC = JPEG.JCS.getYCC(); ++ // No conversions available; image must be YCCA ++ if ((YCC == null) || // We can't do YCC at all ++ (cs != YCC) || ++ (cm.getNumComponents() != numComponents)) { ++ throw new IIOException("Incompatible color conversion"); ++ } + } + break; + default: +@@ -1699,3 +1669,140 @@ + } + } + } ++ ++/** ++ * An internal helper class that wraps producer's iterator ++ * and extracts specifier instances on demand. ++ */ ++class ImageTypeIterator implements Iterator { ++ private Iterator producers; ++ private ImageTypeSpecifier theNext = null; ++ ++ public ImageTypeIterator(Iterator producers) { ++ this.producers = producers; ++ } ++ ++ public boolean hasNext() { ++ if (theNext != null) { ++ return true; ++ } ++ if (!producers.hasNext()) { ++ return false; ++ } ++ do { ++ theNext = producers.next().getType(); ++ } while (theNext == null && producers.hasNext()); ++ ++ return (theNext != null); ++ } ++ ++ public ImageTypeSpecifier next() { ++ if (theNext != null || hasNext()) { ++ ImageTypeSpecifier t = theNext; ++ theNext = null; ++ return t; ++ } else { ++ throw new NoSuchElementException(); ++ } ++ } ++ ++ public void remove() { ++ producers.remove(); ++ } ++} ++ ++/** ++ * An internal helper class that provides means for deferred creation ++ * of ImageTypeSpecifier instance required to describe available ++ * destination types. ++ * ++ * This implementation only supports standard ++ * jpeg color spaces (defined by corresponding JCS color space code). ++ * ++ * To support other color spaces one can override produce() method to ++ * return custom instance of ImageTypeSpecifier. ++ */ ++class ImageTypeProducer { ++ ++ private ImageTypeSpecifier type = null; ++ boolean failed = false; ++ private int csCode; ++ ++ public ImageTypeProducer(int csCode) { ++ this.csCode = csCode; ++ } ++ ++ public ImageTypeProducer() { ++ csCode = -1; // undefined ++ } ++ ++ public synchronized ImageTypeSpecifier getType() { ++ if (!failed && type == null) { ++ try { ++ type = produce(); ++ } catch (Throwable e) { ++ failed = true; ++ } ++ } ++ return type; ++ } ++ ++ private static final ImageTypeProducer [] defaultTypes = ++ new ImageTypeProducer [JPEG.NUM_JCS_CODES]; ++ ++ public synchronized static ImageTypeProducer getTypeProducer(int csCode) { ++ if (csCode < 0 || csCode >= JPEG.NUM_JCS_CODES) { ++ return null; ++ } ++ if (defaultTypes[csCode] == null) { ++ defaultTypes[csCode] = new ImageTypeProducer(csCode); ++ } ++ return defaultTypes[csCode]; ++ } ++ ++ protected ImageTypeSpecifier produce() { ++ switch (csCode) { ++ case JPEG.JCS_GRAYSCALE: ++ return ImageTypeSpecifier.createFromBufferedImageType ++ (BufferedImage.TYPE_BYTE_GRAY); ++ case JPEG.JCS_RGB: ++ return ImageTypeSpecifier.createInterleaved(JPEG.JCS.sRGB, ++ JPEG.bOffsRGB, ++ DataBuffer.TYPE_BYTE, ++ false, ++ false); ++ case JPEG.JCS_RGBA: ++ return ImageTypeSpecifier.createPacked(JPEG.JCS.sRGB, ++ 0xff000000, ++ 0x00ff0000, ++ 0x0000ff00, ++ 0x000000ff, ++ DataBuffer.TYPE_INT, ++ false); ++ case JPEG.JCS_YCC: ++ if (JPEG.JCS.getYCC() != null) { ++ return ImageTypeSpecifier.createInterleaved( ++ JPEG.JCS.getYCC(), ++ JPEG.bandOffsets[2], ++ DataBuffer.TYPE_BYTE, ++ false, ++ false); ++ } else { ++ return null; ++ } ++ case JPEG.JCS_YCCA: ++ if (JPEG.JCS.getYCC() != null) { ++ return ImageTypeSpecifier.createInterleaved( ++ JPEG.JCS.getYCC(), ++ JPEG.bandOffsets[3], ++ DataBuffer.TYPE_BYTE, ++ true, ++ false); ++ } else { ++ return null; ++ } ++ default: ++ return null; ++ } ++ } ++} +diff -Nru openjdk.orig/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java +--- openjdk.orig/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java 2013-08-30 16:19:36.268416189 +0100 ++++ openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java 2013-08-30 16:20:25.453181852 +0100 +@@ -815,7 +815,7 @@ + } + break; + case ColorSpace.TYPE_3CLR: +- if (cs == JPEG.JCS.YCC) { ++ if (cs == JPEG.JCS.getYCC()) { + if (!alpha) { + if (jfif != null) { + convertTosRGB = true; +@@ -1541,7 +1541,7 @@ + } + break; + case ColorSpace.TYPE_3CLR: +- if (cs == JPEG.JCS.YCC) { ++ if (cs == JPEG.JCS.getYCC()) { + if (alpha) { + retval = JPEG.JCS_YCCA; + } else { +@@ -1580,7 +1580,7 @@ + } + break; + case ColorSpace.TYPE_3CLR: +- if (cs == JPEG.JCS.YCC) { ++ if (cs == JPEG.JCS.getYCC()) { + if (alpha) { + retval = JPEG.JCS_YCCA; + } else { +@@ -1626,7 +1626,7 @@ + } + break; + case ColorSpace.TYPE_3CLR: +- if (cs == JPEG.JCS.YCC) { ++ if (cs == JPEG.JCS.getYCC()) { + if (alpha) { + retval = JPEG.JCS_YCCA; + } else { +diff -Nru openjdk.orig/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEG.java openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEG.java +--- openjdk.orig/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEG.java 2013-08-30 16:19:36.256416002 +0100 ++++ openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEG.java 2013-08-30 16:20:25.453181852 +0100 +@@ -215,17 +215,21 @@ + public static class JCS { + public static final ColorSpace sRGB = + ColorSpace.getInstance(ColorSpace.CS_sRGB); +- public static final ColorSpace YCC; + +- static { +- ColorSpace cs = null; +- try { +- cs = ColorSpace.getInstance(ColorSpace.CS_PYCC); +- } catch (IllegalArgumentException e) { +- // PYCC.pf may not always be installed +- } finally { +- YCC = cs; ++ private static ColorSpace YCC = null; ++ private static boolean yccInited = false; ++ ++ public static ColorSpace getYCC() { ++ if (!yccInited) { ++ try { ++ YCC = ColorSpace.getInstance(ColorSpace.CS_PYCC); ++ } catch (IllegalArgumentException e) { ++ // PYCC.pf may not always be installed ++ } finally { ++ yccInited = true; ++ } + } ++ return YCC; + } + } + +diff -Nru openjdk.orig/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java +--- openjdk.orig/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java 2013-08-30 16:19:36.268416189 +0100 ++++ openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java 2013-08-30 16:20:25.453181852 +0100 +@@ -490,7 +490,7 @@ + } + break; + case ColorSpace.TYPE_3CLR: +- if (cs == JPEG.JCS.YCC) { ++ if (cs == JPEG.JCS.getYCC()) { + wantJFIF = false; + componentIDs[0] = (byte) 'Y'; + componentIDs[1] = (byte) 'C'; +diff -Nru openjdk.orig/jdk/src/share/classes/java/awt/color/ICC_Profile.java openjdk/jdk/src/share/classes/java/awt/color/ICC_Profile.java +--- openjdk.orig/jdk/src/share/classes/java/awt/color/ICC_Profile.java 2013-08-30 16:19:36.220415442 +0100 ++++ openjdk/jdk/src/share/classes/java/awt/color/ICC_Profile.java 2013-08-30 16:20:25.453181852 +0100 +@@ -863,11 +863,16 @@ + case ColorSpace.CS_PYCC: + synchronized(ICC_Profile.class) { + if (PYCCprofile == null) { +- ProfileDeferralInfo pInfo = +- new ProfileDeferralInfo("PYCC.pf", +- ColorSpace.TYPE_3CLR, 3, +- CLASS_DISPLAY); +- PYCCprofile = getDeferredInstance(pInfo); ++ if (getProfileFile("PYCC.pf") != null) { ++ ProfileDeferralInfo pInfo = ++ new ProfileDeferralInfo("PYCC.pf", ++ ColorSpace.TYPE_3CLR, 3, ++ CLASS_DISPLAY); ++ PYCCprofile = getDeferredInstance(pInfo); ++ } else { ++ throw new IllegalArgumentException( ++ "Can't load standard profile: PYCC.pf"); ++ } + } + thisProfile = PYCCprofile; + } +diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c +--- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c 2013-08-30 16:19:36.212415317 +0100 ++++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c 2013-08-30 16:21:23.982092967 +0100 +@@ -1818,7 +1818,7 @@ + + + struct jpeg_source_mgr *src; +- JSAMPROW scanLinePtr; ++ JSAMPROW scanLinePtr = NULL; + jint bands[MAX_BANDS]; + int i, j; + jint *body; +@@ -1855,7 +1855,7 @@ + + cinfo = (j_decompress_ptr) data->jpegObj; + +- if ((numBands < 1) || (numBands > cinfo->num_components) || ++ if ((numBands < 1) || + (sourceXStart < 0) || (sourceXStart >= (jint)cinfo->image_width) || + (sourceYStart < 0) || (sourceYStart >= (jint)cinfo->image_height) || + (sourceWidth < 1) || (sourceWidth > (jint)cinfo->image_width) || +@@ -1957,15 +1957,6 @@ + "Invalid number of color components"); + return data->abortFlag; + } +- scanLinePtr = (JSAMPROW)malloc(cinfo->image_width*cinfo->num_components); +- if (scanLinePtr == NULL) { +- RELEASE_ARRAYS(env, data, src->next_input_byte); +- JNU_ThrowByName( env, +- "java/lang/OutOfMemoryError", +- "Reading JPEG Stream"); +- return data->abortFlag; +- } +- + /* Establish the setjmp return context for sun_jpeg_error_exit to use. */ + jerr = (sun_jpeg_error_ptr) cinfo->err; + +@@ -1979,7 +1970,10 @@ + buffer); + JNU_ThrowByName(env, "javax/imageio/IIOException", buffer); + } +- free(scanLinePtr); ++ if (scanLinePtr != NULL) { ++ free(scanLinePtr); ++ scanLinePtr = NULL; ++ } + return data->abortFlag; + } + +@@ -2017,6 +2011,23 @@ + + jpeg_start_decompress(cinfo); + ++ if (numBands != cinfo->output_components) { ++ JNU_ThrowByName(env, "javax/imageio/IIOException", ++ "Invalid argument to native readImage"); ++ return data->abortFlag; ++ } ++ ++ ++ // Allocate a 1-scanline buffer ++ scanLinePtr = (JSAMPROW)malloc(cinfo->image_width*cinfo->output_components); ++ if (scanLinePtr == NULL) { ++ RELEASE_ARRAYS(env, data, src->next_input_byte); ++ JNU_ThrowByName( env, ++ "java/lang/OutOfMemoryError", ++ "Reading JPEG Stream"); ++ return data->abortFlag; ++ } ++ + // loop over progressive passes + done = FALSE; + while (!done) { +@@ -2044,9 +2055,9 @@ + + scanlineLimit = sourceYStart+sourceHeight; + pixelLimit = scanLinePtr +- +(sourceXStart+sourceWidth)*cinfo->num_components; ++ +(sourceXStart+sourceWidth)*cinfo->output_components; + +- pixelStride = stepX*cinfo->num_components; ++ pixelStride = stepX*cinfo->output_components; + targetLine = 0; + + while ((data->abortFlag == JNI_FALSE) +@@ -2068,7 +2079,7 @@ + // Optimization: The component bands are ordered sequentially, + // so we can simply use memcpy() to copy the intermediate + // scanline buffer into the raster. +- in = scanLinePtr + (sourceXStart * cinfo->num_components); ++ in = scanLinePtr + (sourceXStart * cinfo->output_components); + if (pixelLimit > in) { + numBytes = pixelLimit - in; + if (numBytes > data->pixelBuf.byteBufferLength) { +@@ -2078,7 +2089,7 @@ + } + } else { + numBytes = numBands; +- for (in = scanLinePtr+sourceXStart*cinfo->num_components; ++ for (in = scanLinePtr+sourceXStart*cinfo->output_components; + in < pixelLimit && + numBytes <= data->pixelBuf.byteBufferLength; + in += pixelStride) { +diff -Nru openjdk.orig/jdk/test/javax/imageio/plugins/jpeg/ReadAsGrayTest.java openjdk/jdk/test/javax/imageio/plugins/jpeg/ReadAsGrayTest.java +--- openjdk.orig/jdk/test/javax/imageio/plugins/jpeg/ReadAsGrayTest.java 1970-01-01 01:00:00.000000000 +0100 ++++ openjdk/jdk/test/javax/imageio/plugins/jpeg/ReadAsGrayTest.java 2013-08-30 16:20:25.453181852 +0100 +@@ -0,0 +1,179 @@ ++/* ++ * Copyright 2009 Sun Microsystems, Inc. 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 ++ * under the terms of the GNU General Public License version 2 only, as ++ * published by the Free Software Foundation. ++ * ++ * This code is distributed in the hope that it will be useful, but WITHOUT ++ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ++ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ++ * version 2 for more details (a copy is included in the LICENSE file that ++ * accompanied this code). ++ * ++ * You should have received a copy of the GNU General Public License version ++ * 2 along with this work; if not, write to the Free Software Foundation, ++ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ++ * ++ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, ++ * CA 95054 USA or visit www.sun.com if you need additional information or ++ * have any questions. ++ */ ++ ++/** ++ * @test ++ * @bug 4893408 ++ * ++ * @summary Test verifies that Image I/O jpeg reader correctly handles ++ * destination types if number of color components in destination ++ * differs from number of color components in the jpeg image. ++ * Particularly, it verifies reading YCbCr image as a grayscaled ++ * and reading grayscaled jpeg as a RGB. ++ * ++ * @run main ReadAsGrayTest ++ */ ++ ++import java.awt.Color; ++import java.awt.Graphics2D; ++import java.awt.color.ColorSpace; ++import java.awt.image.BufferedImage; ++import java.io.File; ++import java.io.IOException; ++import java.util.Iterator; ++import javax.imageio.ImageIO; ++import javax.imageio.ImageReadParam; ++import javax.imageio.ImageReader; ++import javax.imageio.ImageTypeSpecifier; ++import javax.imageio.stream.ImageInputStream; ++import static java.awt.image.BufferedImage.TYPE_3BYTE_BGR; ++import static java.awt.image.BufferedImage.TYPE_BYTE_GRAY; ++import static java.awt.color.ColorSpace.TYPE_GRAY; ++import static java.awt.color.ColorSpace.CS_sRGB; ++ ++public class ReadAsGrayTest { ++ static Color[] colors = new Color[] { ++ Color.white, Color.red, Color.green, ++ Color.blue, Color.black }; ++ ++ static final int dx = 50; ++ static final int h = 100; ++ ++ static ColorSpace sRGB = ColorSpace.getInstance(CS_sRGB); ++ ++ ++ public static void main(String[] args) throws IOException { ++ System.out.println("Type TYPE_BYTE_GRAY"); ++ doTest(TYPE_BYTE_GRAY); ++ ++ System.out.println("Type TYPE_3BYTE_BGR"); ++ doTest(TYPE_3BYTE_BGR); ++ ++ System.out.println("Test PASSED."); ++ } ++ ++ private static void doTest(int type) throws IOException { ++ BufferedImage src = createTestImage(type); ++ ++ File f = new File("test.jpg"); ++ ++ if (!ImageIO.write(src, "jpg", f)) { ++ throw new RuntimeException("Failed to write test image."); ++ } ++ ++ ImageInputStream iis = ImageIO.createImageInputStream(f); ++ ImageReader reader = ImageIO.getImageReaders(iis).next(); ++ reader.setInput(iis); ++ ++ Iterator types = reader.getImageTypes(0); ++ ImageTypeSpecifier srgb = null; ++ ImageTypeSpecifier gray = null; ++ // look for gray and srgb types ++ while ((srgb == null || gray == null) && types.hasNext()) { ++ ImageTypeSpecifier t = types.next(); ++ if (t.getColorModel().getColorSpace().getType() == TYPE_GRAY) { ++ gray = t; ++ } ++ if (t.getColorModel().getColorSpace() == sRGB) { ++ srgb = t; ++ } ++ } ++ if (gray == null) { ++ throw new RuntimeException("No gray type available."); ++ } ++ if (srgb == null) { ++ throw new RuntimeException("No srgb type available."); ++ } ++ ++ System.out.println("Read as GRAY..."); ++ testType(reader, gray, src); ++ ++ System.out.println("Read as sRGB..."); ++ testType(reader, srgb, src); ++ } ++ ++ private static void testType(ImageReader reader, ++ ImageTypeSpecifier t, ++ BufferedImage src) ++ throws IOException ++ { ++ ImageReadParam p = reader.getDefaultReadParam(); ++ p.setDestinationType(t); ++ BufferedImage dst = reader.read(0, p); ++ ++ verify(src, dst, t); ++ } ++ ++ private static void verify(BufferedImage src, ++ BufferedImage dst, ++ ImageTypeSpecifier type) ++ { ++ BufferedImage test = ++ type.createBufferedImage(src.getWidth(), src.getHeight()); ++ Graphics2D g = test.createGraphics(); ++ g.drawImage(src, 0, 0, null); ++ g.dispose(); ++ ++ for (int i = 0; i < colors.length; i++) { ++ int x = i * dx + dx / 2; ++ int y = h / 2; ++ ++ Color c_test = new Color(test.getRGB(x, y)); ++ Color c_dst = new Color(dst.getRGB(x, y)); ++ ++ if (!compareWithTolerance(c_test, c_dst, 0.01f)) { ++ String msg = String.format("Invalid color: %x instead of %x", ++ c_dst.getRGB(), c_test.getRGB()); ++ throw new RuntimeException("Test failed: " + msg); ++ } ++ } ++ System.out.println("Verified."); ++ } ++ ++ private static boolean compareWithTolerance(Color a, Color b, float delta) { ++ float[] a_rgb = new float[3]; ++ a_rgb = a.getRGBColorComponents(a_rgb); ++ float[] b_rgb = new float[3]; ++ b_rgb = b.getRGBColorComponents(b_rgb); ++ ++ for (int i = 0; i < 3; i++) { ++ if (Math.abs(a_rgb[i] - b_rgb[i]) > delta) { ++ return false; ++ } ++ } ++ return true; ++ } ++ ++ private static BufferedImage createTestImage(int type) { ++ BufferedImage img = new BufferedImage(dx * colors.length, h, type); ++ ++ Graphics2D g = img.createGraphics(); ++ for (int i = 0; i < colors.length; i++) { ++ g.setColor(colors[i]); ++ g.fillRect(i * dx, 0, dx, h); ++ } ++ g.dispose(); ++ ++ return img; ++ } ++} diff -r 3c193afea5f3 -r 222321136c48 patches/openjdk/6631559-dont_load_libjpeg_to_register_imageio_plugins.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/patches/openjdk/6631559-dont_load_libjpeg_to_register_imageio_plugins.patch Tue Sep 03 20:08:26 2013 +0100 @@ -0,0 +1,562 @@ +# HG changeset patch +# User bae +# Date 1233224374 -10800 +# Thu Jan 29 13:19:34 2009 +0300 +# Node ID 36da64dc65454ac7ae6213d2fbb16260318e53dd +# Parent 65cada5a8497277a5efbd022aa3e781a14d5acaf +6631559: Registration of ImageIO plugins should not cause loading of jpeg.dlli and cmm.dll +Reviewed-by: igor, prr + +diff --git a/src/share/classes/com/sun/imageio/plugins/jpeg/JFIFMarkerSegment.java b/src/share/classes/com/sun/imageio/plugins/jpeg/JFIFMarkerSegment.java +--- openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JFIFMarkerSegment.java ++++ openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JFIFMarkerSegment.java +@@ -1003,7 +1003,7 @@ + 3, + new int [] {0, 1, 2}, + null); +- ColorModel cm = new ComponentColorModel(JPEG.sRGB, ++ ColorModel cm = new ComponentColorModel(JPEG.JCS.sRGB, + false, + false, + ColorModel.OPAQUE, +diff --git a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEG.java b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEG.java +--- openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEG.java ++++ openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEG.java +@@ -208,15 +208,24 @@ + + public static final int [] bOffsRGB = { 2, 1, 0 }; + +- protected static final ColorSpace sRGB = +- ColorSpace.getInstance(ColorSpace.CS_sRGB); +- protected static ColorSpace YCC = null; // Can't be final ++ /* These are kept in the inner class to avoid static initialization ++ * of the CMM class until someone actually needs it. ++ * (e.g. do not init CMM on the request for jpeg mime types) ++ */ ++ public static class JCS { ++ public static final ColorSpace sRGB = ++ ColorSpace.getInstance(ColorSpace.CS_sRGB); ++ public static final ColorSpace YCC; + +- static { +- try { +- YCC = ColorSpace.getInstance(ColorSpace.CS_PYCC); +- } catch (IllegalArgumentException e) { +- // PYCC.pf may not always be installed ++ static { ++ ColorSpace cs = null; ++ try { ++ cs = ColorSpace.getInstance(ColorSpace.CS_PYCC); ++ } catch (IllegalArgumentException e) { ++ // PYCC.pf may not always be installed ++ } finally { ++ YCC = cs; ++ } + } + } + +diff --git a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java +--- openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java ++++ openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReader.java +@@ -228,31 +228,31 @@ + (BufferedImage.TYPE_BYTE_GRAY); + defaultTypes[JPEG.JCS_RGB] = + ImageTypeSpecifier.createInterleaved +- (JPEG.sRGB, ++ (JPEG.JCS.sRGB, + JPEG.bOffsRGB, + DataBuffer.TYPE_BYTE, + false, + false); + defaultTypes[JPEG.JCS_RGBA] = + ImageTypeSpecifier.createPacked +- (JPEG.sRGB, ++ (JPEG.JCS.sRGB, + 0xff000000, + 0x00ff0000, + 0x0000ff00, + 0x000000ff, + DataBuffer.TYPE_INT, + false); +- if (JPEG.YCC != null) { ++ if (JPEG.JCS.YCC != null) { + defaultTypes[JPEG.JCS_YCC] = + ImageTypeSpecifier.createInterleaved +- (JPEG.YCC, ++ (JPEG.JCS.YCC, + JPEG.bandOffsets[2], + DataBuffer.TYPE_BYTE, + false, + false); + defaultTypes[JPEG.JCS_YCCA] = + ImageTypeSpecifier.createInterleaved +- (JPEG.YCC, ++ (JPEG.JCS.YCC, + JPEG.bandOffsets[3], + DataBuffer.TYPE_BYTE, + true, +@@ -774,7 +774,7 @@ + case JPEG.JCS_RGB: + list.add(raw); + list.add(getImageType(JPEG.JCS_GRAYSCALE)); +- if (JPEG.YCC != null) { ++ if (JPEG.JCS.YCC != null) { + list.add(getImageType(JPEG.JCS_YCC)); + } + break; +@@ -811,7 +811,7 @@ + } + + list.add(getImageType(JPEG.JCS_GRAYSCALE)); +- if (JPEG.YCC != null) { // Might be null if PYCC.pf not installed ++ if (JPEG.JCS.YCC != null) { // Might be null if PYCC.pf not installed + list.add(getImageType(JPEG.JCS_YCC)); + } + break; +@@ -893,7 +893,7 @@ + (!cs.isCS_sRGB()) && + (cm.getNumComponents() == numComponents)) { + // Target isn't sRGB, so convert from sRGB to the target +- convert = new ColorConvertOp(JPEG.sRGB, cs, null); ++ convert = new ColorConvertOp(JPEG.JCS.sRGB, cs, null); + } else if (csType != ColorSpace.TYPE_RGB) { + throw new IIOException("Incompatible color conversion"); + } +@@ -906,18 +906,18 @@ + } + break; + case JPEG.JCS_YCC: +- if (JPEG.YCC == null) { // We can't do YCC at all ++ if (JPEG.JCS.YCC == null) { // We can't do YCC at all + throw new IIOException("Incompatible color conversion"); + } +- if ((cs != JPEG.YCC) && ++ if ((cs != JPEG.JCS.YCC) && + (cm.getNumComponents() == numComponents)) { +- convert = new ColorConvertOp(JPEG.YCC, cs, null); ++ convert = new ColorConvertOp(JPEG.JCS.YCC, cs, null); + } + break; + case JPEG.JCS_YCCA: + // No conversions available; image must be YCCA +- if ((JPEG.YCC == null) || // We can't do YCC at all +- (cs != JPEG.YCC) || ++ if ((JPEG.JCS.YCC == null) || // We can't do YCC at all ++ (cs != JPEG.JCS.YCC) || + (cm.getNumComponents() != numComponents)) { + throw new IIOException("Incompatible color conversion"); + } +diff --git a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReaderSpi.java b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReaderSpi.java +--- openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReaderSpi.java ++++ openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageReaderSpi.java +@@ -39,8 +39,6 @@ + private static String [] writerSpiNames = + {"com.sun.imageio.plugins.jpeg.JPEGImageWriterSpi"}; + +- private boolean registered = false; +- + public JPEGImageReaderSpi() { + super(JPEG.vendor, + JPEG.version, +@@ -61,26 +59,6 @@ + ); + } + +- public void onRegistration(ServiceRegistry registry, +- Class category) { +- if (registered) { +- return; +- } +- try { +- java.security.AccessController.doPrivileged( +- new sun.security.action.LoadLibraryAction("jpeg")); +- // Stuff it all into one lib for first pass +- //java.security.AccessController.doPrivileged( +- //new sun.security.action.LoadLibraryAction("imageioIJG")); +- } catch (Throwable e) { // Fail on any Throwable +- // if it can't be loaded, deregister and return +- registry.deregisterServiceProvider(this); +- return; +- } +- +- registered = true; +- } +- + public String getDescription(Locale locale) { + return "Standard JPEG Image Reader"; + } +diff --git a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java +--- openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java ++++ openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriter.java +@@ -812,13 +812,13 @@ + } + break; + case ColorSpace.TYPE_3CLR: +- if (cs == JPEG.YCC) { ++ if (cs == JPEG.JCS.YCC) { + if (!alpha) { + if (jfif != null) { + convertTosRGB = true; + convertOp = + new ColorConvertOp(cs, +- JPEG.sRGB, ++ JPEG.JCS.sRGB, + null); + outCsType = JPEG.JCS_YCbCr; + } else if (adobe != null) { +@@ -1494,7 +1494,7 @@ + } + break; + case ColorSpace.TYPE_3CLR: +- if (cs == JPEG.YCC) { ++ if (cs == JPEG.JCS.YCC) { + if (alpha) { + retval = JPEG.JCS_YCCA; + } else { +@@ -1533,7 +1533,7 @@ + } + break; + case ColorSpace.TYPE_3CLR: +- if (cs == JPEG.YCC) { ++ if (cs == JPEG.JCS.YCC) { + if (alpha) { + retval = JPEG.JCS_YCCA; + } else { +@@ -1579,7 +1579,7 @@ + } + break; + case ColorSpace.TYPE_3CLR: +- if (cs == JPEG.YCC) { ++ if (cs == JPEG.JCS.YCC) { + if (alpha) { + retval = JPEG.JCS_YCCA; + } else { +diff --git a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriterSpi.java b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriterSpi.java +--- openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriterSpi.java ++++ openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGImageWriterSpi.java +@@ -42,8 +42,6 @@ + private static String [] readerSpiNames = + {"com.sun.imageio.plugins.jpeg.JPEGImageReaderSpi"}; + +- private boolean registered = false; +- + public JPEGImageWriterSpi() { + super(JPEG.vendor, + JPEG.version, +@@ -68,23 +66,6 @@ + return "Standard JPEG Image Writer"; + } + +- public void onRegistration(ServiceRegistry registry, +- Class category) { +- if (registered) { +- return; +- } +- try { +- java.security.AccessController.doPrivileged( +- new sun.security.action.LoadLibraryAction("jpeg")); +- } catch (Throwable e) { // Fail on any Throwable +- // if it can't be loaded, deregister and return +- registry.deregisterServiceProvider(this); +- return; +- } +- +- registered = true; +- } +- + public boolean isFormatLossless() { + return false; + } +diff --git a/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java b/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java +--- openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java ++++ openjdk/jdk/src/share/classes/com/sun/imageio/plugins/jpeg/JPEGMetadata.java +@@ -490,7 +490,7 @@ + } + break; + case ColorSpace.TYPE_3CLR: +- if (cs == JPEG.YCC) { ++ if (cs == JPEG.JCS.YCC) { + wantJFIF = false; + componentIDs[0] = (byte) 'Y'; + componentIDs[1] = (byte) 'C'; +diff --git a/src/share/classes/javax/imageio/ImageTypeSpecifier.java b/src/share/classes/javax/imageio/ImageTypeSpecifier.java +--- openjdk/jdk/src/share/classes/javax/imageio/ImageTypeSpecifier.java ++++ openjdk/jdk/src/share/classes/javax/imageio/ImageTypeSpecifier.java +@@ -67,126 +67,13 @@ + * BufferedImage types. + */ + private static ImageTypeSpecifier[] BISpecifier; +- ++ private static ColorSpace sRGB; + // Initialize the standard specifiers + static { +- ColorSpace sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB); ++ sRGB = ColorSpace.getInstance(ColorSpace.CS_sRGB); + + BISpecifier = + new ImageTypeSpecifier[BufferedImage.TYPE_BYTE_INDEXED + 1]; +- +- BISpecifier[BufferedImage.TYPE_CUSTOM] = null; +- +- BISpecifier[BufferedImage.TYPE_INT_RGB] = +- createPacked(sRGB, +- 0x00ff0000, +- 0x0000ff00, +- 0x000000ff, +- 0x0, +- DataBuffer.TYPE_INT, +- false); +- +- BISpecifier[BufferedImage.TYPE_INT_ARGB] = +- createPacked(sRGB, +- 0x00ff0000, +- 0x0000ff00, +- 0x000000ff, +- 0xff000000, +- DataBuffer.TYPE_INT, +- false); +- +- BISpecifier[BufferedImage.TYPE_INT_ARGB_PRE] = +- createPacked(sRGB, +- 0x00ff0000, +- 0x0000ff00, +- 0x000000ff, +- 0xff000000, +- DataBuffer.TYPE_INT, +- true); +- +- BISpecifier[BufferedImage.TYPE_INT_BGR] = +- createPacked(sRGB, +- 0x000000ff, +- 0x0000ff00, +- 0x00ff0000, +- 0x0, +- DataBuffer.TYPE_INT, +- false); +- +- int[] bOffsRGB = { 2, 1, 0 }; +- BISpecifier[BufferedImage.TYPE_3BYTE_BGR] = +- createInterleaved(sRGB, +- bOffsRGB, +- DataBuffer.TYPE_BYTE, +- false, +- false); +- +- int[] bOffsABGR = { 3, 2, 1, 0 }; +- BISpecifier[BufferedImage.TYPE_4BYTE_ABGR] = +- createInterleaved(sRGB, +- bOffsABGR, +- DataBuffer.TYPE_BYTE, +- true, +- false); +- +- BISpecifier[BufferedImage.TYPE_4BYTE_ABGR_PRE] = +- createInterleaved(sRGB, +- bOffsABGR, +- DataBuffer.TYPE_BYTE, +- true, +- true); +- +- BISpecifier[BufferedImage.TYPE_USHORT_565_RGB] = +- createPacked(sRGB, +- 0xF800, +- 0x07E0, +- 0x001F, +- 0x0, +- DataBuffer.TYPE_USHORT, +- false); +- +- BISpecifier[BufferedImage.TYPE_USHORT_555_RGB] = +- createPacked(sRGB, +- 0x7C00, +- 0x03E0, +- 0x001F, +- 0x0, +- DataBuffer.TYPE_USHORT, +- false); +- +- BISpecifier[BufferedImage.TYPE_BYTE_GRAY] = +- createGrayscale(8, +- DataBuffer.TYPE_BYTE, +- false); +- +- BISpecifier[BufferedImage.TYPE_USHORT_GRAY] = +- createGrayscale(16, +- DataBuffer.TYPE_USHORT, +- false); +- +- BISpecifier[BufferedImage.TYPE_BYTE_BINARY] = +- createGrayscale(1, +- DataBuffer.TYPE_BYTE, +- false); +- +- BufferedImage bi = +- new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_INDEXED); +- IndexColorModel icm = (IndexColorModel)bi.getColorModel(); +- int mapSize = icm.getMapSize(); +- byte[] redLUT = new byte[mapSize]; +- byte[] greenLUT = new byte[mapSize]; +- byte[] blueLUT = new byte[mapSize]; +- byte[] alphaLUT = new byte[mapSize]; +- +- icm.getReds(redLUT); +- icm.getGreens(greenLUT); +- icm.getBlues(blueLUT); +- icm.getAlphas(alphaLUT); +- +- BISpecifier[BufferedImage.TYPE_BYTE_INDEXED] = +- createIndexed(redLUT, greenLUT, blueLUT, alphaLUT, +- 8, +- DataBuffer.TYPE_BYTE); + } + + /** +@@ -1011,7 +898,7 @@ + ImageTypeSpecifier createFromBufferedImageType(int bufferedImageType) { + if (bufferedImageType >= BufferedImage.TYPE_INT_RGB && + bufferedImageType <= BufferedImage.TYPE_BYTE_INDEXED) { +- return BISpecifier[bufferedImageType]; ++ return getSpecifier(bufferedImageType); + } else if (bufferedImageType == BufferedImage.TYPE_CUSTOM) { + throw new IllegalArgumentException("Cannot create from TYPE_CUSTOM!"); + } else { +@@ -1041,7 +928,7 @@ + if (image instanceof BufferedImage) { + int bufferedImageType = ((BufferedImage)image).getType(); + if (bufferedImageType != BufferedImage.TYPE_CUSTOM) { +- return BISpecifier[bufferedImageType]; ++ return getSpecifier(bufferedImageType); + } + } + +@@ -1225,4 +1112,130 @@ + public int hashCode() { + return (9 * colorModel.hashCode()) + (14 * sampleModel.hashCode()); + } ++ ++ private static ImageTypeSpecifier getSpecifier(int type) { ++ if (BISpecifier[type] == null) { ++ BISpecifier[type] = createSpecifier(type); ++ } ++ return BISpecifier[type]; ++ } ++ ++ private static ImageTypeSpecifier createSpecifier(int type) { ++ switch(type) { ++ case BufferedImage.TYPE_INT_RGB: ++ return createPacked(sRGB, ++ 0x00ff0000, ++ 0x0000ff00, ++ 0x000000ff, ++ 0x0, ++ DataBuffer.TYPE_INT, ++ false); ++ ++ case BufferedImage.TYPE_INT_ARGB: ++ return createPacked(sRGB, ++ 0x00ff0000, ++ 0x0000ff00, ++ 0x000000ff, ++ 0xff000000, ++ DataBuffer.TYPE_INT, ++ false); ++ ++ case BufferedImage.TYPE_INT_ARGB_PRE: ++ return createPacked(sRGB, ++ 0x00ff0000, ++ 0x0000ff00, ++ 0x000000ff, ++ 0xff000000, ++ DataBuffer.TYPE_INT, ++ true); ++ ++ case BufferedImage.TYPE_INT_BGR: ++ return createPacked(sRGB, ++ 0x000000ff, ++ 0x0000ff00, ++ 0x00ff0000, ++ 0x0, ++ DataBuffer.TYPE_INT, ++ false); ++ ++ case BufferedImage.TYPE_3BYTE_BGR: ++ return createInterleaved(sRGB, ++ new int[] { 2, 1, 0 }, ++ DataBuffer.TYPE_BYTE, ++ false, ++ false); ++ ++ case BufferedImage.TYPE_4BYTE_ABGR: ++ return createInterleaved(sRGB, ++ new int[] { 3, 2, 1, 0 }, ++ DataBuffer.TYPE_BYTE, ++ true, ++ false); ++ ++ case BufferedImage.TYPE_4BYTE_ABGR_PRE: ++ return createInterleaved(sRGB, ++ new int[] { 3, 2, 1, 0 }, ++ DataBuffer.TYPE_BYTE, ++ true, ++ true); ++ ++ case BufferedImage.TYPE_USHORT_565_RGB: ++ return createPacked(sRGB, ++ 0xF800, ++ 0x07E0, ++ 0x001F, ++ 0x0, ++ DataBuffer.TYPE_USHORT, ++ false); ++ ++ case BufferedImage.TYPE_USHORT_555_RGB: ++ return createPacked(sRGB, ++ 0x7C00, ++ 0x03E0, ++ 0x001F, ++ 0x0, ++ DataBuffer.TYPE_USHORT, ++ false); ++ ++ case BufferedImage.TYPE_BYTE_GRAY: ++ return createGrayscale(8, ++ DataBuffer.TYPE_BYTE, ++ false); ++ ++ case BufferedImage.TYPE_USHORT_GRAY: ++ return createGrayscale(16, ++ DataBuffer.TYPE_USHORT, ++ false); ++ ++ case BufferedImage.TYPE_BYTE_BINARY: ++ return createGrayscale(1, ++ DataBuffer.TYPE_BYTE, ++ false); ++ ++ case BufferedImage.TYPE_BYTE_INDEXED: ++ { ++ ++ BufferedImage bi = ++ new BufferedImage(1, 1, BufferedImage.TYPE_BYTE_INDEXED); ++ IndexColorModel icm = (IndexColorModel)bi.getColorModel(); ++ int mapSize = icm.getMapSize(); ++ byte[] redLUT = new byte[mapSize]; ++ byte[] greenLUT = new byte[mapSize]; ++ byte[] blueLUT = new byte[mapSize]; ++ byte[] alphaLUT = new byte[mapSize]; ++ ++ icm.getReds(redLUT); ++ icm.getGreens(greenLUT); ++ icm.getBlues(blueLUT); ++ icm.getAlphas(alphaLUT); ++ ++ return createIndexed(redLUT, greenLUT, blueLUT, alphaLUT, ++ 8, ++ DataBuffer.TYPE_BYTE); ++ } ++ default: ++ throw new IllegalArgumentException("Invalid BufferedImage type!"); ++ } ++ } ++ + } diff -r 3c193afea5f3 -r 222321136c48 patches/openjdk/6791502-invalid_icc_profile.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/patches/openjdk/6791502-invalid_icc_profile.patch Tue Sep 03 20:08:26 2013 +0100 @@ -0,0 +1,269 @@ +diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c +--- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c 2013-08-30 15:28:52.333056323 +0100 ++++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c 2013-08-30 15:31:17.627316140 +0100 +@@ -403,7 +403,7 @@ + data->jpegObj = cinfo; + cinfo->client_data = data; + +-#ifdef DEBUG ++#ifdef DEBUG_IIO_JPEG + printf("new structures: data is %p, cinfo is %p\n", data, cinfo); + #endif + +@@ -686,7 +686,7 @@ + j_decompress_ptr decomp; + + qlen = (*env)->GetArrayLength(env, qtables); +-#ifdef DEBUG ++#ifdef DEBUG_IIO_JPEG + printf("in setQTables, qlen = %d, write is %d\n", qlen, write); + #endif + if (qlen > NUM_QUANT_TBLS) { +@@ -912,7 +912,7 @@ + return FALSE; + } + +-#ifdef DEBUG ++#ifdef DEBUG_IIO_JPEG + printf("Filling input buffer, remaining skip is %ld, ", + sb->remaining_skip); + printf("Buffer length is %d\n", sb->bufferLength); +@@ -942,7 +942,7 @@ + cinfo->err->error_exit((j_common_ptr) cinfo); + } + +-#ifdef DEBUG ++#ifdef DEBUG_IIO_JPEG + printf("Buffer filled. ret = %d\n", ret); + #endif + /* +@@ -953,7 +953,7 @@ + */ + if (ret <= 0) { + jobject reader = data->imageIOobj; +-#ifdef DEBUG ++#ifdef DEBUG_IIO_JPEG + printf("YO! Early EOI! ret = %d\n", ret); + #endif + RELEASE_ARRAYS(env, data, src->next_input_byte); +@@ -1252,21 +1252,24 @@ + { + jpeg_saved_marker_ptr marker; + int num_markers = 0; ++ int num_found_markers = 0; + int seq_no; + JOCTET *icc_data; ++ JOCTET *dst_ptr; + unsigned int total_length; + #define MAX_SEQ_NO 255 // sufficient since marker numbers are bytes +- char marker_present[MAX_SEQ_NO+1]; // 1 if marker found +- unsigned int data_length[MAX_SEQ_NO+1]; // size of profile data in marker +- unsigned int data_offset[MAX_SEQ_NO+1]; // offset for data in marker ++ jpeg_saved_marker_ptr icc_markers[MAX_SEQ_NO + 1]; ++ int first; // index of the first marker in the icc_markers array ++ int last; // index of the last marker in the icc_markers array + jbyteArray data = NULL; + + /* This first pass over the saved markers discovers whether there are + * any ICC markers and verifies the consistency of the marker numbering. + */ + +- for (seq_no = 1; seq_no <= MAX_SEQ_NO; seq_no++) +- marker_present[seq_no] = 0; ++ for (seq_no = 0; seq_no <= MAX_SEQ_NO; seq_no++) ++ icc_markers[seq_no] = NULL; ++ + + for (marker = cinfo->marker_list; marker != NULL; marker = marker->next) { + if (marker_is_icc(marker)) { +@@ -1278,37 +1281,58 @@ + return NULL; + } + seq_no = GETJOCTET(marker->data[12]); +- if (seq_no <= 0 || seq_no > num_markers) { ++ ++ /* Some third-party tools produce images with profile chunk ++ * numeration started from zero. It is inconsistent with ICC ++ * spec, but seems to be recognized by majority of image ++ * processing tools, so we should be more tolerant to this ++ * departure from the spec. ++ */ ++ if (seq_no < 0 || seq_no > num_markers) { + JNU_ThrowByName(env, "javax/imageio/IIOException", + "Invalid icc profile: bad sequence number"); + return NULL; + } +- if (marker_present[seq_no]) { ++ if (icc_markers[seq_no] != NULL) { + JNU_ThrowByName(env, "javax/imageio/IIOException", + "Invalid icc profile: duplicate sequence numbers"); + return NULL; + } +- marker_present[seq_no] = 1; +- data_length[seq_no] = marker->data_length - ICC_OVERHEAD_LEN; ++ icc_markers[seq_no] = marker; ++ num_found_markers ++; + } + } + + if (num_markers == 0) + return NULL; // There is no profile + +- /* Check for missing markers, count total space needed, +- * compute offset of each marker's part of the data. +- */ ++ if (num_markers != num_found_markers) { ++ JNU_ThrowByName(env, "javax/imageio/IIOException", ++ "Invalid icc profile: invalid number of icc markers"); ++ return NULL; ++ } ++ ++ first = icc_markers[0] ? 0 : 1; ++ last = num_found_markers + first; + ++ /* Check for missing markers, count total space needed. ++ */ + total_length = 0; +- for (seq_no = 1; seq_no <= num_markers; seq_no++) { +- if (marker_present[seq_no] == 0) { ++ for (seq_no = first; seq_no < last; seq_no++) { ++ unsigned int length; ++ if (icc_markers[seq_no] == NULL) { + JNU_ThrowByName(env, "javax/imageio/IIOException", + "Invalid icc profile: missing sequence number"); + return NULL; + } +- data_offset[seq_no] = total_length; +- total_length += data_length[seq_no]; ++ /* check the data length correctness */ ++ length = icc_markers[seq_no]->data_length; ++ if (ICC_OVERHEAD_LEN > length || length > MAX_BYTES_IN_MARKER) { ++ JNU_ThrowByName(env, "javax/imageio/IIOException", ++ "Invalid icc profile: invalid data length"); ++ return NULL; ++ } ++ total_length += (length - ICC_OVERHEAD_LEN); + } + + if (total_length <= 0) { +@@ -1337,19 +1361,14 @@ + } + + /* and fill it in */ +- for (marker = cinfo->marker_list; marker != NULL; marker = marker->next) { +- if (marker_is_icc(marker)) { +- JOCTET FAR *src_ptr; +- JOCTET *dst_ptr; +- unsigned int length; +- seq_no = GETJOCTET(marker->data[12]); +- dst_ptr = icc_data + data_offset[seq_no]; +- src_ptr = marker->data + ICC_OVERHEAD_LEN; +- length = data_length[seq_no]; +- while (length--) { +- *dst_ptr++ = *src_ptr++; +- } +- } ++ dst_ptr = icc_data; ++ for (seq_no = first; seq_no < last; seq_no++) { ++ JOCTET FAR *src_ptr = icc_markers[seq_no]->data + ICC_OVERHEAD_LEN; ++ unsigned int length = ++ icc_markers[seq_no]->data_length - ICC_OVERHEAD_LEN; ++ ++ memcpy(dst_ptr, src_ptr, length); ++ dst_ptr += length; + } + + /* finally, unpin the array */ +@@ -1565,6 +1584,7 @@ + j_decompress_ptr cinfo; + struct jpeg_source_mgr *src; + sun_jpeg_error_ptr jerr; ++ jbyteArray profileData = NULL; + + if (data == NULL) { + JNU_ThrowByName(env, +@@ -1592,7 +1612,7 @@ + return retval; + } + +-#ifdef DEBUG ++#ifdef DEBUG_IIO_JPEG + printf("In readImageHeader, data is %p cinfo is %p\n", data, cinfo); + printf("clearFirst is %d\n", clearFirst); + #endif +@@ -1619,7 +1639,7 @@ + if (ret == JPEG_HEADER_TABLES_ONLY) { + retval = JNI_TRUE; + imageio_term_source(cinfo); // Pushback remaining buffer contents +-#ifdef DEBUG ++#ifdef DEBUG_IIO_JPEG + printf("just read tables-only image; q table 0 at %p\n", + cinfo->quant_tbl_ptrs[0]); + #endif +@@ -1726,6 +1746,14 @@ + } + } + RELEASE_ARRAYS(env, data, src->next_input_byte); ++ ++ /* read icc profile data */ ++ profileData = read_icc_profile(env, cinfo); ++ ++ if ((*env)->ExceptionCheck(env)) { ++ return retval; ++ } ++ + (*env)->CallVoidMethod(env, this, + JPEGImageReader_setImageDataID, + cinfo->image_width, +@@ -1733,7 +1761,7 @@ + cinfo->jpeg_color_space, + cinfo->out_color_space, + cinfo->num_components, +- read_icc_profile(env, cinfo)); ++ profileData); + if (reset) { + jpeg_abort_decompress(cinfo); + } +@@ -1898,7 +1926,7 @@ + (*env)->ReleaseIntArrayElements(env, bandSizes, + bandSize, JNI_ABORT); + +-#ifdef DEBUG ++#ifdef DEBUG_IIO_JPEG + printf("---- in reader.read ----\n"); + printf("numBands is %d\n", numBands); + printf("bands array: "); +@@ -2578,7 +2606,7 @@ + + data->streamBuf.suspendable = FALSE; + if (qtables != NULL) { +-#ifdef DEBUG ++#ifdef DEBUG_IIO_JPEG + printf("in writeTables: qtables not NULL\n"); + #endif + setQTables(env, (j_common_ptr) cinfo, qtables, TRUE); +@@ -2854,7 +2882,7 @@ + + cinfo->restart_interval = restartInterval; + +-#ifdef DEBUG ++#ifdef DEBUG_IIO_JPEG + printf("writer setup complete, starting compressor\n"); + #endif + +@@ -2905,13 +2933,13 @@ + for (; (in < pixelLimit) && (out < scanLineLimit); in += pixelStride) { + for (i = 0; i < numBands; i++) { + *out++ = data->scale[i][*(in+i)]; +-#ifdef DEBUG ++#ifdef DEBUG_IIO_JPEG + if (in == data->pixelBuf.buf.bp){ // Just the first pixel + printf("in %d -> out %d, ", *(in+i), *(out-i-1)); + } + #endif + } +-#ifdef DEBUG ++#ifdef DEBUG_IIO_JPEG + if (in == data->pixelBuf.buf.bp){ // Just the first pixel + printf("\n"); + } diff -r 3c193afea5f3 -r 222321136c48 patches/openjdk/6793818-jpegimagereader_too_greedy.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/patches/openjdk/6793818-jpegimagereader_too_greedy.patch Tue Sep 03 20:08:26 2013 +0100 @@ -0,0 +1,228 @@ +diff -Nru openjdk.orig/jdk/src/share/classes/java/awt/color/ICC_Profile.java openjdk/jdk/src/share/classes/java/awt/color/ICC_Profile.java +--- openjdk.orig/jdk/src/share/classes/java/awt/color/ICC_Profile.java 2012-10-26 19:25:49.000000000 +0100 ++++ openjdk/jdk/src/share/classes/java/awt/color/ICC_Profile.java 2013-08-30 15:54:06.720611009 +0100 +@@ -737,7 +737,7 @@ + ICC_Profile(ProfileDeferralInfo pdi) { + this.deferralInfo = pdi; + this.profileActivator = new ProfileActivator() { +- public void activate() { ++ public void activate() throws ProfileDataException { + activateDeferredProfile(); + } + }; +@@ -830,20 +830,16 @@ + case ColorSpace.CS_sRGB: + synchronized(ICC_Profile.class) { + if (sRGBprofile == null) { +- try { +- /* +- * Deferral is only used for standard profiles. +- * Enabling the appropriate access privileges is handled +- * at a lower level. +- */ +- sRGBprofile = getDeferredInstance( +- new ProfileDeferralInfo("sRGB.pf", +- ColorSpace.TYPE_RGB, +- 3, CLASS_DISPLAY)); +- } catch (IOException e) { +- throw new IllegalArgumentException( +- "Can't load standard profile: sRGB.pf"); +- } ++ /* ++ * Deferral is only used for standard profiles. ++ * Enabling the appropriate access privileges is handled ++ * at a lower level. ++ */ ++ ProfileDeferralInfo pInfo = ++ new ProfileDeferralInfo("sRGB.pf", ++ ColorSpace.TYPE_RGB, 3, ++ CLASS_DISPLAY); ++ sRGBprofile = getDeferredInstance(pInfo); + } + thisProfile = sRGBprofile; + } +@@ -853,7 +849,11 @@ + case ColorSpace.CS_CIEXYZ: + synchronized(ICC_Profile.class) { + if (XYZprofile == null) { +- XYZprofile = getStandardProfile("CIEXYZ.pf"); ++ ProfileDeferralInfo pInfo = ++ new ProfileDeferralInfo("CIEXYZ.pf", ++ ColorSpace.TYPE_XYZ, 3, ++ CLASS_DISPLAY); ++ XYZprofile = getDeferredInstance(pInfo); + } + thisProfile = XYZprofile; + } +@@ -863,7 +863,11 @@ + case ColorSpace.CS_PYCC: + synchronized(ICC_Profile.class) { + if (PYCCprofile == null) { +- PYCCprofile = getStandardProfile("PYCC.pf"); ++ ProfileDeferralInfo pInfo = ++ new ProfileDeferralInfo("PYCC.pf", ++ ColorSpace.TYPE_3CLR, 3, ++ CLASS_DISPLAY); ++ PYCCprofile = getDeferredInstance(pInfo); + } + thisProfile = PYCCprofile; + } +@@ -873,7 +877,11 @@ + case ColorSpace.CS_GRAY: + synchronized(ICC_Profile.class) { + if (GRAYprofile == null) { +- GRAYprofile = getStandardProfile("GRAY.pf"); ++ ProfileDeferralInfo pInfo = ++ new ProfileDeferralInfo("GRAY.pf", ++ ColorSpace.TYPE_GRAY, 1, ++ CLASS_DISPLAY); ++ GRAYprofile = getDeferredInstance(pInfo); + } + thisProfile = GRAYprofile; + } +@@ -883,7 +891,11 @@ + case ColorSpace.CS_LINEAR_RGB: + synchronized(ICC_Profile.class) { + if (LINEAR_RGBprofile == null) { +- LINEAR_RGBprofile = getStandardProfile("LINEAR_RGB.pf"); ++ ProfileDeferralInfo pInfo = ++ new ProfileDeferralInfo("LINEAR_RGB.pf", ++ ColorSpace.TYPE_RGB, 3, ++ CLASS_DISPLAY); ++ LINEAR_RGBprofile = getDeferredInstance(pInfo); + } + thisProfile = LINEAR_RGBprofile; + } +@@ -1047,9 +1059,7 @@ + * code will take care of access privileges. + * @see activateDeferredProfile() + */ +- static ICC_Profile getDeferredInstance(ProfileDeferralInfo pdi) +- throws IOException { +- ++ static ICC_Profile getDeferredInstance(ProfileDeferralInfo pdi) { + if (!ProfileDeferralMgr.deferring) { + return getStandardProfile(pdi.filename); + } +@@ -1063,7 +1073,7 @@ + } + + +- void activateDeferredProfile() { ++ void activateDeferredProfile() throws ProfileDataException { + byte profileData[]; + FileInputStream fis; + final String fileName = deferralInfo.filename; +@@ -1082,25 +1092,29 @@ + } + }; + if ((fis = AccessController.doPrivileged(pa)) == null) { +- throw new IllegalArgumentException("Cannot open file " + fileName); ++ throw new ProfileDataException("Cannot open file " + fileName); + } + try { + profileData = getProfileDataFromStream(fis); + fis.close(); /* close the file */ + } + catch (IOException e) { +- throw new IllegalArgumentException("Invalid ICC Profile Data" + +- fileName); ++ ProfileDataException pde = new ++ ProfileDataException("Invalid ICC Profile Data" + fileName); ++ pde.initCause(e); ++ throw pde; + } + if (profileData == null) { +- throw new IllegalArgumentException("Invalid ICC Profile Data" + ++ throw new ProfileDataException("Invalid ICC Profile Data" + + fileName); + } + try { + ID = CMSManager.getModule().loadProfile(profileData); + } catch (CMMException c) { +- throw new IllegalArgumentException("Invalid ICC Profile Data" + +- fileName); ++ ProfileDataException pde = new ++ ProfileDataException("Invalid ICC Profile Data" + fileName); ++ pde.initCause(c); ++ throw pde; + } + } + +diff -Nru openjdk.orig/jdk/src/share/classes/sun/java2d/cmm/ProfileActivator.java openjdk/jdk/src/share/classes/sun/java2d/cmm/ProfileActivator.java +--- openjdk.orig/jdk/src/share/classes/sun/java2d/cmm/ProfileActivator.java 2012-10-26 19:26:01.000000000 +0100 ++++ openjdk/jdk/src/share/classes/sun/java2d/cmm/ProfileActivator.java 2013-08-30 15:51:48.658462916 +0100 +@@ -25,6 +25,7 @@ + + package sun.java2d.cmm; + ++import java.awt.color.ProfileDataException; + + /** + * An interface to allow the ProfileDeferralMgr to activate a +@@ -35,6 +36,6 @@ + /** + * Activate a previously deferred ICC_Profile object. + */ +- public void activate(); ++ public void activate() throws ProfileDataException; + + } +diff -Nru openjdk.orig/jdk/src/share/classes/sun/java2d/cmm/ProfileDeferralMgr.java openjdk/jdk/src/share/classes/sun/java2d/cmm/ProfileDeferralMgr.java +--- openjdk.orig/jdk/src/share/classes/sun/java2d/cmm/ProfileDeferralMgr.java 2012-10-26 19:26:01.000000000 +0100 ++++ openjdk/jdk/src/share/classes/sun/java2d/cmm/ProfileDeferralMgr.java 2013-08-30 15:51:48.658462916 +0100 +@@ -25,6 +25,7 @@ + + package sun.java2d.cmm; + ++import java.awt.color.ProfileDataException; + import java.util.Vector; + + +@@ -39,7 +40,7 @@ + public class ProfileDeferralMgr { + + public static boolean deferring = true; +- private static Vector aVector; ++ private static Vector aVector; + + /** + * Records a ProfileActivator object whose activate method will +@@ -51,7 +52,7 @@ + return; + } + if (aVector == null) { +- aVector = new Vector(3, 3); ++ aVector = new Vector(3, 3); + } + aVector.addElement(pa); + return; +@@ -89,8 +90,26 @@ + return; + } + n = aVector.size(); +- for (i = 0; i < n; i++) { +- ((ProfileActivator) aVector.get(i)).activate(); ++ for (ProfileActivator pa : aVector) { ++ try { ++ pa.activate(); ++ } catch (ProfileDataException e) { ++ /* ++ * Ignore profile activation error for now: ++ * such exception is pssible due to absence ++ * or corruption of standard color profile. ++ * As for now we expect all profiles should ++ * be shiped with jre and presence of this ++ * exception is indication of some configuration ++ * problem in jre installation. ++ * ++ * NB: we still are greedy loading deferred profiles ++ * and load them all if any of them is needed. ++ * Therefore broken profile (if any) might be never used. ++ * If there will be attempt to use broken profile then ++ * it will result in CMMException. ++ */ ++ } + } + aVector.removeAllElements(); + aVector = null; diff -r 3c193afea5f3 -r 222321136c48 patches/openjdk/6888215-jpeg_memory_leak.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/patches/openjdk/6888215-jpeg_memory_leak.patch Tue Sep 03 20:08:26 2013 +0100 @@ -0,0 +1,56 @@ +# HG changeset patch +# User bae +# Date 1256299191 -14400 +# Fri Oct 23 15:59:51 2009 +0400 +# Node ID 5fc5d3243a5c68774277a18938c6f496cabd7f94 +# Parent c579f830770746e8b679ebd3a8a40eb5253e16e5 +6888215: memory leak in jpeg plugin +Reviewed-by: igor, prr + +diff --git a/src/share/native/sun/awt/image/jpeg/imageioJPEG.c b/src/share/native/sun/awt/image/jpeg/imageioJPEG.c +--- openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c ++++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c +@@ -1437,6 +1437,7 @@ + JNU_ThrowByName( env, + "java/lang/OutOfMemoryError", + "Initializing Reader"); ++ free(cinfo); + return 0; + } + +@@ -1473,6 +1474,7 @@ + JNU_ThrowByName(env, + "java/lang/OutOfMemoryError", + "Initializing Reader"); ++ imageio_dispose((j_common_ptr)cinfo); + return 0; + } + cinfo->src->bytes_in_buffer = 0; +@@ -1489,6 +1491,7 @@ + JNU_ThrowByName( env, + "java/lang/OutOfMemoryError", + "Initializing Reader"); ++ imageio_dispose((j_common_ptr)cinfo); + return 0; + } + return (jlong) ret; +@@ -2420,8 +2423,7 @@ + JNU_ThrowByName( env, + "java/lang/OutOfMemoryError", + "Initializing Writer"); +- free(cinfo); +- free(jerr); ++ imageio_dispose((j_common_ptr)cinfo); + return 0; + } + +@@ -2439,8 +2441,7 @@ + JNU_ThrowByName( env, + "java/lang/OutOfMemoryError", + "Initializing Writer"); +- free(cinfo); +- free(jerr); ++ imageio_dispose((j_common_ptr)cinfo); + return 0; + } + return (jlong) ret; diff -r 3c193afea5f3 -r 222321136c48 patches/openjdk/6989760-native_warnings.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/patches/openjdk/6989760-native_warnings.patch Tue Sep 03 20:08:26 2013 +0100 @@ -0,0 +1,42 @@ +# HG changeset patch +# User bae +# Date 1300292466 -10800 +# Wed Mar 16 19:21:06 2011 +0300 +# Node ID 5c61c31d2621e53e4fe011d235b7f05d0a40ba63 +# Parent 253f3bc64961944b1886a243a662bd929e9ab605 +6989760: cmm native compiler warnings +Reviewed-by: prr, ohair + +diff --git a/make/sun/cmm/kcms/Makefile b/make/sun/cmm/kcms/Makefile +--- openjdk/jdk/make/sun/cmm/kcms/Makefile ++++ openjdk/jdk/make/sun/cmm/kcms/Makefile +@@ -72,7 +72,8 @@ + # Extra rules + # + ifeq ($(PLATFORM), linux) +-LDLIBS += -lpthread ++ LDLIBS += -lpthread ++ OTHER_CFLAGS += -Wno-missing-field-initializers + endif + + clean clobber:: +@@ -104,6 +105,5 @@ + + endif # PLATFORM + +-#CFLAGS += -DJAVACMM -DFUT_CALC_EX -DNO_FUT_GCONST +-CFLAGS += -DFUT_CALC_EX -DNO_FUT_GCONST ++CFLAGS += -DJAVACMM -DFUT_CALC_EX -DNO_FUT_GCONST + +diff --git a/src/share/native/sun/awt/image/jpeg/imageioJPEG.c b/src/share/native/sun/awt/image/jpeg/imageioJPEG.c +--- openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c ++++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c +@@ -2657,7 +2657,7 @@ + (destWidth < 0) || (destWidth > srcWidth) || + (destHeight < 0) || + (stepX < 0) || (stepY < 0) || +- ((scanLineSize / numBands) < destWidth)) /* destWidth causes an integer overflow */ ++ ((INT_MAX / numBands) < destWidth)) /* destWidth causes an integer overflow */ + { + JNU_ThrowByName(env, "javax/imageio/IIOException", + "Invalid argument to native writeImage"); diff -r 3c193afea5f3 -r 222321136c48 patches/openjdk/6989774-imageio_compiler_warnings.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/patches/openjdk/6989774-imageio_compiler_warnings.patch Tue Sep 03 20:08:26 2013 +0100 @@ -0,0 +1,649 @@ +diff -Nru openjdk.orig/jdk/make/sun/jpeg/Makefile openjdk/jdk/make/sun/jpeg/Makefile +--- openjdk.orig/jdk/make/sun/jpeg/Makefile 2012-10-26 19:25:41.000000000 +0100 ++++ openjdk/jdk/make/sun/jpeg/Makefile 2013-08-30 16:29:41.181832003 +0100 +@@ -65,6 +65,19 @@ + FILES_reorder += reorder-$(ARCH) + endif + endif ++ ++ifeq ($(PLATFORM), linux) ++ ++ # Suppress gcc warnings like "variable might be clobbered by 'longjmp' ++ # or 'vfork'": this warning indicates that some variable is placed to ++ # a register by optimized compiler and it's value might be lost on longjmp(). ++ # Recommended way to avoid such warning is to declare the variable as ++ # volatile to prevent the optimization. However, this approach does not ++ # work because we have to declare all variables as volatile in result. ++ ++ OTHER_CFLAGS += -Wno-clobbered ++endif ++ + include $(BUILDDIR)/common/Mapfile-vers.gmk + include $(BUILDDIR)/common/Library.gmk + +diff -Nru openjdk.orig/jdk/make/sun/jpeg/reorder-i586 openjdk/jdk/make/sun/jpeg/reorder-i586 +--- openjdk.orig/jdk/make/sun/jpeg/reorder-i586 2012-10-26 19:25:41.000000000 +0100 ++++ openjdk/jdk/make/sun/jpeg/reorder-i586 2013-08-30 16:29:41.181832003 +0100 +@@ -22,7 +22,7 @@ + text: .text%alloc_small: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jmemmgr.o; + text: .text%reset_marker_reader: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; + text: .text%jIInCtlr; +-text: .text%GET_ARRAYS: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jpegdecoder.o; ++# text: .text%GET_ARRAYS: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jpegdecoder.o; + text: .text%jReadHeader; + text: .text%jConsumeInput; + text: .text%reset_input_controller: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdinput.o; +@@ -30,36 +30,36 @@ + text: .text%sun_jpeg_init_source; + text: .text%consume_markers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdinput.o; + text: .text%read_markers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; +-text: .text%first_marker: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; ++# text: .text%first_marker: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; + text: .text%sun_jpeg_fill_input_buffer; +-text: .text%RELEASE_ARRAYS: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jpegdecoder.o; +-text: .text%get_soi: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; ++# text: .text%RELEASE_ARRAYS: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jpegdecoder.o; ++# text: .text%get_soi: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; + text: .text%emit_message: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jerror.o; +-text: .text%next_marker: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; ++# text: .text%next_marker: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; + text: .text%get_interesting_appn: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; +-text: .text%examine_app0: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; ++# text: .text%examine_app0: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; + text: .text%skip_variable: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; + text: .text%sun_jpeg_skip_input_data; +-text: .text%examine_app14: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; ++# text: .text%examine_app14: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; + text: .text%get_dqt: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; + text: .text%jAlcQTable; + text: .text%get_sof: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; +-text: .text%get_dri: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; ++# text: .text%get_dri: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; + text: .text%get_dht: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; + text: .text%jAlcHTable; + text: .text%get_sos: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; +-text: .text%initial_setup: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdinput.o; ++# text: .text%initial_setup: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdinput.o; + text: .text%jDivRound; +-text: .text%default_decompress_parms: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdapimin.o; ++# text: .text%default_decompress_parms: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdapimin.o; + text: .text%jHasMultScn; + text: .text%jStrtDecompress; + text: .text%jIDMaster; +-text: .text%master_selection: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmaster.o; ++# text: .text%master_selection: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmaster.o; + text: .text%jCalcDimensions; +-text: .text%use_merged_upsample: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmaster.o; +-text: .text%prepare_range_limit_table: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmaster.o; ++# text: .text%use_merged_upsample: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmaster.o; ++# text: .text%prepare_range_limit_table: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmaster.o; + text: .text%jIDColor; +-text: .text%build_ycc_rgb_table: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdcolor.o; ++# text: .text%build_ycc_rgb_table: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdcolor.o; + text: .text%jIUpsampler; + text: .text%jRound; + text: .text%alloc_sarray: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jmemmgr.o; +@@ -70,16 +70,16 @@ + text: .text%jIHDecoder; + text: .text%jIDCoefC; + text: .text%jIDMainC; +-text: .text%alloc_funny_pointers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmainct.o; ++# text: .text%alloc_funny_pointers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmainct.o; + text: .text%realize_virt_arrays: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jmemmgr.o; + text: .text%start_input_pass: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdinput.o; +-text: .text%per_scan_setup: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdinput.o; +-text: .text%latch_quant_tables: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdinput.o; ++# text: .text%per_scan_setup: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdinput.o; ++# text: .text%latch_quant_tables: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdinput.o; + text: .text%start_pass_huff_decoder: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdhuff.o; + text: .text%jMkDDerived; + text: .text%start_input_pass: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdcoefct.o; +-text: .text%start_iMCU_row: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdcoefct.o; +-text: .text%output_pass_setup: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdapistd.o; ++# text: .text%start_iMCU_row: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdcoefct.o; ++# text: .text%output_pass_setup: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdapistd.o; + text: .text%prepare_for_output_pass: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmaster.o; + text: .text%start_pass: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jddctmgr.o; + text: .text%start_output_pass: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdcoefct.o; +@@ -87,7 +87,7 @@ + text: .text%start_pass_upsample: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdsample.o; + text: .text%start_pass_dpost: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdpostct.o; + text: .text%start_pass_main: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmainct.o; +-text: .text%make_funny_pointers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmainct.o; ++# text: .text%make_funny_pointers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmainct.o; + text: .text%jReadScanlines; + text: .text%process_data_context_main: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmainct.o; + text: .text%decompress_onepass: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdcoefct.o; +@@ -100,11 +100,11 @@ + text: .text%fullsize_upsample: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdsample.o; + text: .text%h2v2_fancy_upsample: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdsample.o; + text: .text%ycc_rgb_convert: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdcolor.o; +-text: .text%set_wraparound_pointers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmainct.o; +-text: .text%process_restart: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdhuff.o; ++# text: .text%set_wraparound_pointers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmainct.o; ++# text: .text%process_restart: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdhuff.o; + text: .text%read_restart_marker: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; + text: .text%finish_input_pass: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdinput.o; +-text: .text%set_bottom_pointers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmainct.o; ++# text: .text%set_bottom_pointers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmainct.o; + text: .text%jFinDecompress; + text: .text%finish_output_pass: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmaster.o; + text: .text%sun_jpeg_term_source; +diff -Nru openjdk.orig/jdk/make/sun/jpeg/reorder-sparc openjdk/jdk/make/sun/jpeg/reorder-sparc +--- openjdk.orig/jdk/make/sun/jpeg/reorder-sparc 2012-10-26 19:25:41.000000000 +0100 ++++ openjdk/jdk/make/sun/jpeg/reorder-sparc 2013-08-30 16:29:41.181832003 +0100 +@@ -30,10 +30,10 @@ + text: .text%sun_jpeg_init_source; + text: .text%consume_markers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdinput.o; + text: .text%read_markers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; +-text: .text%first_marker: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; ++# text: .text%first_marker: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; + text: .text%sun_jpeg_fill_input_buffer; + text: .text%RELEASE_ARRAYS: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jpegdecoder.o; +-text: .text%get_soi: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; ++# text: .text%get_soi: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; + text: .text%emit_message: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jerror.o; + text: .text%next_marker: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; + text: .text%get_interesting_appn: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; +@@ -44,7 +44,7 @@ + text: .text%get_dqt: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; + text: .text%jAlcQTable; + text: .text%get_sof: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; +-text: .text%get_dri: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; ++# text: .text%get_dri: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; + text: .text%get_dht: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; + text: .text%jAlcHTable; + text: .text%get_sos: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; +@@ -56,10 +56,10 @@ + text: .text%jIDMaster; + text: .text%master_selection: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmaster.o; + text: .text%jCalcDimensions; +-text: .text%use_merged_upsample: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmaster.o; +-text: .text%prepare_range_limit_table: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmaster.o; ++# text: .text%use_merged_upsample: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmaster.o; ++# text: .text%prepare_range_limit_table: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmaster.o; + text: .text%jIDColor; +-text: .text%build_ycc_rgb_table: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdcolor.o; ++# text: .text%build_ycc_rgb_table: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdcolor.o; + text: .text%jIUpsampler; + text: .text%jRound; + text: .text%alloc_sarray: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jmemmgr.o; +@@ -78,7 +78,7 @@ + text: .text%start_pass_huff_decoder: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdhuff.o; + text: .text%jMkDDerived; + text: .text%start_input_pass: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdcoefct.o; +-text: .text%start_iMCU_row: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdcoefct.o; ++# text: .text%start_iMCU_row: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdcoefct.o; + text: .text%output_pass_setup: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdapistd.o; + text: .text%prepare_for_output_pass: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmaster.o; + text: .text%start_pass: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jddctmgr.o; +@@ -100,11 +100,11 @@ + text: .text%fullsize_upsample: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdsample.o; + text: .text%h2v2_fancy_upsample: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdsample.o; + text: .text%ycc_rgb_convert: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdcolor.o; +-text: .text%set_wraparound_pointers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmainct.o; +-text: .text%process_restart: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdhuff.o; ++# text: .text%set_wraparound_pointers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmainct.o; ++#text: .text%process_restart: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdhuff.o; + text: .text%read_restart_marker: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmarker.o; + text: .text%finish_input_pass: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdinput.o; +-text: .text%set_bottom_pointers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmainct.o; ++# text: .text%set_bottom_pointers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmainct.o; + text: .text%jFinDecompress; + text: .text%finish_output_pass: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj/jdmaster.o; + text: .text%sun_jpeg_term_source; +diff -Nru openjdk.orig/jdk/make/sun/jpeg/reorder-sparcv9 openjdk/jdk/make/sun/jpeg/reorder-sparcv9 +--- openjdk.orig/jdk/make/sun/jpeg/reorder-sparcv9 2012-10-26 19:25:41.000000000 +0100 ++++ openjdk/jdk/make/sun/jpeg/reorder-sparcv9 2013-08-30 16:29:41.181832003 +0100 +@@ -30,10 +30,10 @@ + text: .text%sun_jpeg_init_source; + text: .text%consume_markers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdinput.o; + text: .text%read_markers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmarker.o; +-text: .text%first_marker: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmarker.o; ++# text: .text%first_marker: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmarker.o; + text: .text%sun_jpeg_fill_input_buffer; + text: .text%RELEASE_ARRAYS: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jpegdecoder.o; +-text: .text%get_soi: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmarker.o; ++# text: .text%get_soi: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmarker.o; + text: .text%emit_message: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jerror.o; + text: .text%next_marker: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmarker.o; + text: .text%get_interesting_appn: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmarker.o; +@@ -44,7 +44,7 @@ + text: .text%get_dqt: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmarker.o; + text: .text%jAlcQTable; + text: .text%get_sof: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmarker.o; +-text: .text%get_dri: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmarker.o; ++# text: .text%get_dri: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmarker.o; + text: .text%get_dht: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmarker.o; + text: .text%jAlcHTable; + text: .text%get_sos: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmarker.o; +@@ -56,10 +56,10 @@ + text: .text%jIDMaster; + text: .text%master_selection: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmaster.o; + text: .text%jCalcDimensions; +-text: .text%use_merged_upsample: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmaster.o; +-text: .text%prepare_range_limit_table: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmaster.o; ++# text: .text%use_merged_upsample: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmaster.o; ++# text: .text%prepare_range_limit_table: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmaster.o; + text: .text%jIDColor; +-text: .text%build_ycc_rgb_table: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdcolor.o; ++# text: .text%build_ycc_rgb_table: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdcolor.o; + text: .text%jIUpsampler; + text: .text%jRound; + text: .text%alloc_sarray: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jmemmgr.o; +@@ -78,7 +78,7 @@ + text: .text%start_pass_huff_decoder: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdhuff.o; + text: .text%jMkDDerived; + text: .text%start_input_pass: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdcoefct.o; +-text: .text%start_iMCU_row: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdcoefct.o; ++# text: .text%start_iMCU_row: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdcoefct.o; + text: .text%output_pass_setup: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdapistd.o; + text: .text%prepare_for_output_pass: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmaster.o; + text: .text%start_pass: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jddctmgr.o; +@@ -100,11 +100,11 @@ + text: .text%fullsize_upsample: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdsample.o; + text: .text%h2v2_fancy_upsample: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdsample.o; + text: .text%ycc_rgb_convert: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdcolor.o; +-text: .text%set_wraparound_pointers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmainct.o; ++# text: .text%set_wraparound_pointers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmainct.o; + text: .text%process_restart: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdhuff.o; + text: .text%read_restart_marker: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmarker.o; + text: .text%finish_input_pass: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdinput.o; +-text: .text%set_bottom_pointers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmainct.o; ++# text: .text%set_bottom_pointers: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmainct.o; + text: .text%jFinDecompress; + text: .text%finish_output_pass: OUTPUTDIR/tmp/sun/sun.awt/jpeg/obj64/jdmaster.o; + text: .text%sun_jpeg_term_source; +diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c +--- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c 2013-08-30 16:26:19.446692090 +0100 ++++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c 2013-08-30 16:31:55.715925913 +0100 +@@ -110,8 +110,8 @@ + jobject stream; // ImageInputStream or ImageOutputStream + jbyteArray hstreamBuffer; // Handle to a Java buffer for the stream + JOCTET *buf; // Pinned buffer pointer */ +- int bufferOffset; // holds offset between unpin and the next pin +- int bufferLength; // Allocated, nut just used ++ size_t bufferOffset; // holds offset between unpin and the next pin ++ size_t bufferLength; // Allocated, nut just used + int suspendable; // Set to true to suspend input + long remaining_skip; // Used only on input + } streamBuffer, *streamBufferPtr; +@@ -130,7 +130,7 @@ + * Used to signal that no data need be restored from an unpin to a pin. + * I.e. the buffer is empty. + */ +-#define NO_DATA -1 ++#define NO_DATA ((size_t)-1) + + // Forward reference + static void resetStreamBuffer(JNIEnv *env, streamBufferPtr sb); +@@ -393,7 +393,6 @@ + static imageIODataPtr initImageioData (JNIEnv *env, + j_common_ptr cinfo, + jobject obj) { +- int i, j; + + imageIODataPtr data = (imageIODataPtr) malloc (sizeof(imageIOData)); + if (data == NULL) { +@@ -992,7 +991,7 @@ + streamBufferPtr sb = &data->streamBuf; + JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); + jint ret; +- int offset, buflen; ++ size_t offset, buflen; + + /* + * The original (jpegdecoder.c) had code here that called +@@ -1530,7 +1529,7 @@ + imageio_dispose((j_common_ptr)cinfo); + return 0; + } +- return (jlong) ret; ++ return ptr_to_jlong(ret); + } + + /* +@@ -1544,7 +1543,7 @@ + jobject this, + jlong ptr) { + +- imageIODataPtr data = (imageIODataPtr) ptr; ++ imageIODataPtr data = (imageIODataPtr)jlong_to_ptr(ptr); + j_common_ptr cinfo; + + if (data == NULL) { +@@ -1583,7 +1582,7 @@ + int h_samp0, h_samp1, h_samp2; + int v_samp0, v_samp1, v_samp2; + jboolean retval = JNI_FALSE; +- imageIODataPtr data = (imageIODataPtr) ptr; ++ imageIODataPtr data = (imageIODataPtr)jlong_to_ptr(ptr); + j_decompress_ptr cinfo; + struct jpeg_source_mgr *src; + sun_jpeg_error_ptr jerr; +@@ -1781,7 +1780,7 @@ + jlong ptr, + jint code) { + +- imageIODataPtr data = (imageIODataPtr) ptr; ++ imageIODataPtr data = (imageIODataPtr)jlong_to_ptr(ptr); + j_decompress_ptr cinfo; + + if (data == NULL) { +@@ -1823,7 +1822,7 @@ + struct jpeg_source_mgr *src; + JSAMPROW scanLinePtr = NULL; + jint bands[MAX_BANDS]; +- int i, j; ++ int i; + jint *body; + int scanlineLimit; + int pixelStride; +@@ -1833,14 +1832,12 @@ + pixelBufferPtr pb; + sun_jpeg_error_ptr jerr; + boolean done; +- jint *bandSize; +- int maxBandValue, halfMaxBandValue; + boolean mustScale = FALSE; + boolean progressive = FALSE; + boolean orderedBands = TRUE; +- imageIODataPtr data = (imageIODataPtr) ptr; ++ imageIODataPtr data = (imageIODataPtr)jlong_to_ptr(ptr); + j_decompress_ptr cinfo; +- unsigned int numBytes; ++ size_t numBytes; + + /* verify the inputs */ + +@@ -1872,10 +1869,10 @@ + return JNI_FALSE; + } + +- if (stepX > cinfo->image_width) { ++ if (stepX > (jint)cinfo->image_width) { + stepX = cinfo->image_width; + } +- if (stepY > cinfo->image_height) { ++ if (stepY > (jint)cinfo->image_height) { + stepY = cinfo->image_height; + } + +@@ -2172,7 +2169,7 @@ + jobject this, + jlong ptr) { + +- imageIODataPtr data = (imageIODataPtr) ptr; ++ imageIODataPtr data = (imageIODataPtr)jlong_to_ptr(ptr); + + if (data == NULL) { + JNU_ThrowByName(env, +@@ -2190,7 +2187,7 @@ + (JNIEnv *env, + jobject this, + jlong ptr) { +- imageIODataPtr data = (imageIODataPtr) ptr; ++ imageIODataPtr data = (imageIODataPtr)jlong_to_ptr(ptr); + j_decompress_ptr cinfo; + + if (data == NULL) { +@@ -2212,7 +2209,7 @@ + jobject this, + jlong ptr) { + +- imageIODataPtr data = (imageIODataPtr) ptr; ++ imageIODataPtr data = (imageIODataPtr)jlong_to_ptr(ptr); + j_decompress_ptr cinfo; + sun_jpeg_error_ptr jerr; + +@@ -2285,7 +2282,7 @@ + jclass reader, + jlong ptr) { + +- imageIODataPtr data = (imageIODataPtr) ptr; ++ imageIODataPtr data = (imageIODataPtr)jlong_to_ptr(ptr); + j_common_ptr info = destroyImageioData(env, data); + + imageio_dispose(info); +@@ -2370,8 +2367,8 @@ + JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); + + /* find out how much needs to be written */ +- jint datacount = sb->bufferLength - dest->free_in_buffer; +- ++ /* this conversion from size_t to jint is safe, because the lenght of the buffer is limited by jint */ ++ jint datacount = (jint)(sb->bufferLength - dest->free_in_buffer); + if (datacount != 0) { + RELEASE_ARRAYS(env, data, (const JOCTET *)(dest->next_output_byte)); + +@@ -2537,7 +2534,7 @@ + imageio_dispose((j_common_ptr)cinfo); + return 0; + } +- return (jlong) ret; ++ return ptr_to_jlong(ret); + } + + JNIEXPORT void JNICALL +@@ -2546,7 +2543,7 @@ + jobject this, + jlong ptr) { + +- imageIODataPtr data = (imageIODataPtr) ptr; ++ imageIODataPtr data = (imageIODataPtr)jlong_to_ptr(ptr); + j_compress_ptr cinfo; + + if (data == NULL) { +@@ -2577,7 +2574,7 @@ + + struct jpeg_destination_mgr *dest; + sun_jpeg_error_ptr jerr; +- imageIODataPtr data = (imageIODataPtr) ptr; ++ imageIODataPtr data = (imageIODataPtr)jlong_to_ptr(ptr); + j_compress_ptr cinfo; + + if (data == NULL) { +@@ -2677,7 +2674,7 @@ + jint *bandSize; + int maxBandValue, halfMaxBandValue; + boolean mustScale = FALSE; +- imageIODataPtr data = (imageIODataPtr) ptr; ++ imageIODataPtr data = (imageIODataPtr)jlong_to_ptr(ptr); + j_compress_ptr cinfo; + + /* verify the inputs */ +@@ -2783,6 +2780,16 @@ + buffer); + JNU_ThrowByName(env, "javax/imageio/IIOException", buffer); + } ++ ++ if (scale != NULL) { ++ for (i = 0; i < numBands; i++) { ++ if (scale[i] != NULL) { ++ free(scale[i]); ++ } ++ } ++ free(scale); ++ } ++ + free(scanLinePtr); + return data->abortFlag; + } +@@ -2989,7 +2996,7 @@ + jobject this, + jlong ptr) { + +- imageIODataPtr data = (imageIODataPtr) ptr; ++ imageIODataPtr data = (imageIODataPtr)jlong_to_ptr(ptr); + + if (data == NULL) { + JNU_ThrowByName(env, +@@ -3006,7 +3013,7 @@ + (JNIEnv *env, + jobject this, + jlong ptr) { +- imageIODataPtr data = (imageIODataPtr) ptr; ++ imageIODataPtr data = (imageIODataPtr)jlong_to_ptr(ptr); + j_compress_ptr cinfo; + + if (data == NULL) { +@@ -3038,7 +3045,7 @@ + jclass writer, + jlong ptr) { + +- imageIODataPtr data = (imageIODataPtr) ptr; ++ imageIODataPtr data = (imageIODataPtr)jlong_to_ptr(ptr); + j_common_ptr info = destroyImageioData(env, data); + + imageio_dispose(info); +diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jdmarker.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/jdmarker.c +--- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jdmarker.c 2012-10-26 19:26:12.000000000 +0100 ++++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jdmarker.c 2013-08-30 16:29:41.181832003 +0100 +@@ -1325,14 +1325,14 @@ + unsigned int length_limit) + { + my_marker_ptr marker = (my_marker_ptr) cinfo->marker; +- long maxlength; ++ size_t maxlength; + jpeg_marker_parser_method processor; + + /* Length limit mustn't be larger than what we can allocate + * (should only be a concern in a 16-bit environment). + */ + maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct); +- if (((long) length_limit) > maxlength) ++ if (length_limit > maxlength) + length_limit = (unsigned int) maxlength; + + /* Choose processor routine to use. +diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jmemmgr.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/jmemmgr.c +--- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jmemmgr.c 2012-10-26 19:26:12.000000000 +0100 ++++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jmemmgr.c 2013-08-30 16:29:41.181832003 +0100 +@@ -133,7 +133,7 @@ + jvirt_barray_ptr virt_barray_list; + + /* This counts total space obtained from jpeg_get_small/large */ +- long total_space_allocated; ++ size_t total_space_allocated; + + /* alloc_sarray and alloc_barray set this value for use by virtual + * array routines. +@@ -588,8 +588,8 @@ + /* Allocate the in-memory buffers for any unrealized virtual arrays */ + { + my_mem_ptr mem = (my_mem_ptr) cinfo->mem; +- long space_per_minheight, maximum_space, avail_mem; +- long minheights, max_minheights; ++ size_t space_per_minheight, maximum_space, avail_mem; ++ size_t minheights, max_minheights; + jvirt_sarray_ptr sptr; + jvirt_barray_ptr bptr; + +@@ -1032,7 +1032,7 @@ + jinit_memory_mgr (j_common_ptr cinfo) + { + my_mem_ptr mem; +- long max_to_use; ++ size_t max_to_use; + int pool; + size_t test_mac; + +@@ -1109,8 +1109,10 @@ + + if ((memenv = getenv("JPEGMEM")) != NULL) { + char ch = 'x'; ++ unsigned int mem_max = 0u; + +- if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) { ++ if (sscanf(memenv, "%u%c", &mem_max, &ch) > 0) { ++ max_to_use = (size_t)mem_max; + if (ch == 'm' || ch == 'M') + max_to_use *= 1000L; + mem->pub.max_memory_to_use = max_to_use * 1000L; +diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jmemnobs.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/jmemnobs.c +--- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jmemnobs.c 2012-10-26 19:26:12.000000000 +0100 ++++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jmemnobs.c 2013-08-30 16:29:41.181832003 +0100 +@@ -73,9 +73,9 @@ + * Here we always say, "we got all you want bud!" + */ + +-GLOBAL(long) +-jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed, +- long max_bytes_needed, long already_allocated) ++GLOBAL(size_t) ++jpeg_mem_available (j_common_ptr cinfo, size_t min_bytes_needed, ++ size_t max_bytes_needed, size_t already_allocated) + { + return max_bytes_needed; + } +@@ -100,7 +100,7 @@ + * cleanup required. Here, there isn't any. + */ + +-GLOBAL(long) ++GLOBAL(size_t) + jpeg_mem_init (j_common_ptr cinfo) + { + return 0; /* just set max_memory_to_use to 0 */ +diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jmemsys.h openjdk/jdk/src/share/native/sun/awt/image/jpeg/jmemsys.h +--- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jmemsys.h 2012-10-26 19:26:12.000000000 +0100 ++++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jmemsys.h 2013-08-30 16:29:41.181832003 +0100 +@@ -104,10 +104,10 @@ + * Conversely, zero may be returned to always use the minimum amount of memory. + */ + +-EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo, +- long min_bytes_needed, +- long max_bytes_needed, +- long already_allocated)); ++EXTERN(size_t) jpeg_mem_available JPP((j_common_ptr cinfo, ++ size_t min_bytes_needed, ++ size_t max_bytes_needed, ++ size_t already_allocated)); + + + /* +@@ -198,5 +198,5 @@ + * all opened backing-store objects have been closed. + */ + +-EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo)); ++EXTERN(size_t) jpeg_mem_init JPP((j_common_ptr cinfo)); + EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo)); +diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c +--- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c 2012-10-26 19:26:12.000000000 +0100 ++++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jpegdecoder.c 2013-08-30 16:29:41.181832003 +0100 +@@ -328,7 +328,7 @@ + if ((*env)->ExceptionOccurred(env) || !GET_ARRAYS(env, src)) { + cinfo->err->error_exit((struct jpeg_common_struct *) cinfo); + } +- if (ret <= src->remaining_skip) { ++ if (ret < 0 || (unsigned int)ret <= src->remaining_skip) { + return; + } + if (src->remaining_skip) { +@@ -397,7 +397,7 @@ + } + num_bytes += src->remaining_skip; + src->remaining_skip = 0; +- ret = src->pub.bytes_in_buffer; ++ ret = (int)src->pub.bytes_in_buffer; /* this conversion is safe, because capacity of the buffer is limited by jnit */ + if (ret >= num_bytes) { + src->pub.next_input_byte += num_bytes; + src->pub.bytes_in_buffer -= num_bytes; +diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jpeglib.h openjdk/jdk/src/share/native/sun/awt/image/jpeg/jpeglib.h +--- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/jpeglib.h 2012-10-26 19:26:12.000000000 +0100 ++++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/jpeglib.h 2013-08-30 16:29:41.181832003 +0100 +@@ -800,10 +800,10 @@ + * used for virtual-array buffers.) May be changed by outer application + * after creating the JPEG object. + */ +- long max_memory_to_use; ++ size_t max_memory_to_use; + + /* Maximum allocation request accepted by alloc_large. */ +- long max_alloc_chunk; ++ size_t max_alloc_chunk; + }; + + diff -r 3c193afea5f3 -r 222321136c48 patches/openjdk/7013519-integer_overflows.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/patches/openjdk/7013519-integer_overflows.patch Tue Sep 03 20:08:26 2013 +0100 @@ -0,0 +1,17 @@ +diff -Nru openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c +--- openjdk.orig/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c 2013-08-30 17:45:18.973172706 +0100 ++++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c 2013-08-30 18:36:21.704926778 +0100 +@@ -2017,6 +2017,13 @@ + return data->abortFlag; + } + ++ if (cinfo->output_components <= 0 || ++ cinfo->image_width > (0xffffffffu / (unsigned int)cinfo->output_components)) ++ { ++ JNU_ThrowByName(env, "javax/imageio/IIOException", ++ "Invalid number of output components"); ++ return data->abortFlag; ++ } + + // Allocate a 1-scanline buffer + scanLinePtr = (JSAMPROW)malloc(cinfo->image_width*cinfo->output_components); diff -r 3c193afea5f3 -r 222321136c48 patches/openjdk/7018912-potential_buffer_overruns_in_jpeg.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/patches/openjdk/7018912-potential_buffer_overruns_in_jpeg.patch Tue Sep 03 20:08:26 2013 +0100 @@ -0,0 +1,21 @@ +# HG changeset patch +# User bae +# Date 1297939346 -10800 +# Thu Feb 17 13:42:26 2011 +0300 +# Node ID e45f7d50dbc9789ddc69d7cd76bf72bde47ef3d6 +# Parent b04dafeda7063e07662508419415fca4a9989b24 +7018912: [parfait] potential buffer overruns in imageio jpeg +Reviewed-by: jgodinez, prr + +diff --git a/src/share/native/sun/awt/image/jpeg/imageioJPEG.c b/src/share/native/sun/awt/image/jpeg/imageioJPEG.c +--- openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c ++++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c +@@ -1846,7 +1846,7 @@ + + cinfo = (j_decompress_ptr) data->jpegObj; + +- if ((numBands < 1) || ++ if ((numBands < 1) || (numBands > MAX_BANDS) || + (sourceXStart < 0) || (sourceXStart >= (jint)cinfo->image_width) || + (sourceYStart < 0) || (sourceYStart >= (jint)cinfo->image_height) || + (sourceWidth < 1) || (sourceWidth > (jint)cinfo->image_width) || diff -r 3c193afea5f3 -r 222321136c48 patches/openjdk/8005194-scale_memory_leak.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/patches/openjdk/8005194-scale_memory_leak.patch Tue Sep 03 20:08:26 2013 +0100 @@ -0,0 +1,25 @@ +# HG changeset patch +# User jgodinez +# Date 1360190702 28800 +# Wed Feb 06 14:45:02 2013 -0800 +# Node ID 37719b174e8705b5b7f01d55bceaeb1213805032 +# Parent 8fc3e4015b090ebe974a842cf7f065e5af7429aa +8005194: [parfait] #353 sun/awt/image/jpeg/imageioJPEG.c Memory leak of pointer 'scale' allocated with calloc() +Reviewed-by: prr, vadim +Contributed-by: jia-hong.chen@oracle.com + +diff --git a/src/share/native/sun/awt/image/jpeg/imageioJPEG.c b/src/share/native/sun/awt/image/jpeg/imageioJPEG.c +--- openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c ++++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c +@@ -2694,6 +2694,11 @@ + scale[i] = (UINT8*) malloc((maxBandValue + 1) * sizeof(UINT8)); + + if (scale[i] == NULL) { ++ // Cleanup before throwing an out of memory exception ++ for (j = 0; j < i; j++) { ++ free(scale[j]); ++ } ++ free(scale); + JNU_ThrowByName( env, "java/lang/OutOfMemoryError", + "Writing JPEG Stream"); + return JNI_FALSE; diff -r 3c193afea5f3 -r 222321136c48 patches/openjdk/8020983-outofmemoryerror_jpegimagewriter.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/patches/openjdk/8020983-outofmemoryerror_jpegimagewriter.patch Tue Sep 03 20:08:26 2013 +0100 @@ -0,0 +1,320 @@ +# HG changeset patch +# User bae +# Date 1375300838 -14400 +# Thu Aug 01 00:00:38 2013 +0400 +# Node ID 46b203b37e061aa0a95992cfcfa0d4066422ada7 +# Parent cd7a4d0b218f98511068d8336aa3f4cbaf10b128 +8020983: OutOfMemoryError caused by non garbage collected JPEGImageWriter Instances +Reviewed-by: prr, flar + +diff --git a/src/share/native/sun/awt/image/jpeg/imageioJPEG.c b/src/share/native/sun/awt/image/jpeg/imageioJPEG.c +--- openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c ++++ openjdk/jdk/src/share/native/sun/awt/image/jpeg/imageioJPEG.c +@@ -106,7 +106,7 @@ + /******************** StreamBuffer definition ************************/ + + typedef struct streamBufferStruct { +- jobject stream; // ImageInputStream or ImageOutputStream ++ jweak ioRef; // weak reference to a provider of I/O routines + jbyteArray hstreamBuffer; // Handle to a Java buffer for the stream + JOCTET *buf; // Pinned buffer pointer */ + size_t bufferOffset; // holds offset between unpin and the next pin +@@ -125,6 +125,15 @@ + */ + #define STREAMBUF_SIZE 4096 + ++#define GET_IO_REF(io_name) \ ++ do { \ ++ if ((*env)->IsSameObject(env, sb->ioRef, NULL) || \ ++ ((io_name) = (*env)->NewLocalRef(env, sb->ioRef)) == NULL) \ ++ { \ ++ cinfo->err->error_exit((j_common_ptr) cinfo); \ ++ } \ ++ } while (0) \ ++ + /* + * Used to signal that no data need be restored from an unpin to a pin. + * I.e. the buffer is empty. +@@ -159,7 +168,7 @@ + } + + +- sb->stream = NULL; ++ sb->ioRef = NULL; + + sb->buf = NULL; + +@@ -191,9 +200,9 @@ + * All other state is reset. + */ + static void resetStreamBuffer(JNIEnv *env, streamBufferPtr sb) { +- if (sb->stream != NULL) { +- (*env)->DeleteGlobalRef(env, sb->stream); +- sb->stream = NULL; ++ if (sb->ioRef != NULL) { ++ (*env)->DeleteWeakGlobalRef(env, sb->ioRef); ++ sb->ioRef = NULL; + } + unpinStreamBuffer(env, sb, NULL); + sb->bufferOffset = NO_DATA; +@@ -571,7 +580,7 @@ + static void imageio_set_stream(JNIEnv *env, + j_common_ptr cinfo, + imageIODataPtr data, +- jobject stream){ ++ jobject io){ + streamBufferPtr sb; + sun_jpeg_error_ptr jerr; + +@@ -579,13 +588,13 @@ + + resetStreamBuffer(env, sb); // Removes any old stream + +- /* Now we need a new global reference for the stream */ +- if (stream != NULL) { // Fix for 4411955 +- sb->stream = (*env)->NewGlobalRef(env, stream); +- if (sb->stream == NULL) { ++ /* Now we need a new weak global reference for the I/O provider */ ++ if (io != NULL) { // Fix for 4411955 ++ sb->ioRef = (*env)->NewWeakGlobalRef(env, io); ++ if (sb->ioRef == NULL) { + JNU_ThrowByName(env, + "java/lang/OutOfMemoryError", +- "Setting Stream"); ++ "Setting I/O provider"); + return; + } + } +@@ -895,6 +904,7 @@ + streamBufferPtr sb = &data->streamBuf; + JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); + int ret; ++ jobject input = NULL; + + /* This is where input suspends */ + if (sb->suspendable) { +@@ -920,9 +930,11 @@ + * Now fill a complete buffer, or as much of one as the stream + * will give us if we are near the end. + */ ++ GET_IO_REF(input); ++ + RELEASE_ARRAYS(env, data, src->next_input_byte); + ret = (*env)->CallIntMethod(env, +- sb->stream, ++ input, + JPEGImageReader_readInputDataID, + sb->hstreamBuffer, 0, + sb->bufferLength); +@@ -982,6 +994,7 @@ + JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); + jint ret; + size_t offset, buflen; ++ jobject input = NULL; + + /* + * The original (jpegdecoder.c) had code here that called +@@ -1003,6 +1016,9 @@ + if (src->next_input_byte > sb->buf) { + memcpy(sb->buf, src->next_input_byte, offset); + } ++ ++ GET_IO_REF(input); ++ + RELEASE_ARRAYS(env, data, src->next_input_byte); + buflen = sb->bufferLength - offset; + if (buflen <= 0) { +@@ -1012,7 +1028,7 @@ + return; + } + +- ret = (*env)->CallIntMethod(env, sb->stream, ++ ret = (*env)->CallIntMethod(env, input, + JPEGImageReader_readInputDataID, + sb->hstreamBuffer, + offset, buflen); +@@ -1075,6 +1091,7 @@ + JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); + jlong ret; + jobject reader; ++ jobject input = NULL; + + if (num_bytes < 0) { + return; +@@ -1104,9 +1121,11 @@ + return; + } + ++ GET_IO_REF(input); ++ + RELEASE_ARRAYS(env, data, src->next_input_byte); + ret = (*env)->CallLongMethod(env, +- sb->stream, ++ input, + JPEGImageReader_skipInputBytesID, + (jlong) num_bytes); + if ((*env)->ExceptionOccurred(env) +@@ -2285,11 +2304,14 @@ + imageIODataPtr data = (imageIODataPtr) cinfo->client_data; + streamBufferPtr sb = &data->streamBuf; + JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); ++ jobject output = NULL; ++ ++ GET_IO_REF(output); + + RELEASE_ARRAYS(env, data, (const JOCTET *)(dest->next_output_byte)); + + (*env)->CallVoidMethod(env, +- sb->stream, ++ output, + JPEGImageWriter_writeOutputDataID, + sb->hstreamBuffer, + 0, +@@ -2322,11 +2344,16 @@ + /* find out how much needs to be written */ + /* this conversion from size_t to jint is safe, because the lenght of the buffer is limited by jint */ + jint datacount = (jint)(sb->bufferLength - dest->free_in_buffer); ++ + if (datacount != 0) { ++ jobject output = NULL; ++ ++ GET_IO_REF(output); ++ + RELEASE_ARRAYS(env, data, (const JOCTET *)(dest->next_output_byte)); + + (*env)->CallVoidMethod(env, +- sb->stream, ++ output, + JPEGImageWriter_writeOutputDataID, + sb->hstreamBuffer, + 0, +diff --git a/test/javax/imageio/plugins/jpeg/JpegWriterLeakTest.java b/test/javax/imageio/plugins/jpeg/JpegWriterLeakTest.java +new file mode 100644 +--- /dev/null ++++ openjdk/jdk/test/javax/imageio/plugins/jpeg/JpegWriterLeakTest.java +@@ -0,0 +1,125 @@ ++/* ++ * Copyright (c) 2013, 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 ++ * under the terms of the GNU General Public License version 2 only, as ++ * published by the Free Software Foundation. ++ * ++ * This code is distributed in the hope that it will be useful, but WITHOUT ++ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ++ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ++ * version 2 for more details (a copy is included in the LICENSE file that ++ * accompanied this code). ++ * ++ * You should have received a copy of the GNU General Public License version ++ * 2 along with this work; if not, write to the Free Software Foundation, ++ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ++ * ++ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ++ * or visit www.oracle.com if you need additional information or have any ++ * questions. ++ */ ++ ++/** ++ * @test ++ * @bug 8020983 ++ * @summary Test verifies that jpeg writer instances are collected ++ * even if destroy() or reset() methods is not invoked. ++ * ++ * @run main JpegWriterLeakTest ++ */ ++ ++import java.awt.Color; ++import java.awt.Graphics2D; ++import java.awt.image.BufferedImage; ++import java.io.ByteArrayOutputStream; ++import java.io.IOException; ++import java.lang.ref.Reference; ++import java.lang.ref.ReferenceQueue; ++import java.lang.ref.WeakReference; ++import java.util.ArrayList; ++import java.util.Random; ++import javax.imageio.ImageIO; ++import javax.imageio.ImageWriter; ++import javax.imageio.stream.ImageOutputStream; ++ ++public class JpegWriterLeakTest { ++ ++ public static void main(String[] args) { ++ final ReferenceQueue queue = new ReferenceQueue<>(); ++ final ArrayList> refs = new ArrayList<>(); ++ ++ int count = 2; ++ ++ do { ++ ImageWriter writer = ++ ImageIO.getImageWritersByFormatName("jpeg").next(); ++ ++ final WeakReference ref = ++ new WeakReference<>(writer, queue); ++ ++ refs.add(ref); ++ ++ ++ try { ++ final ImageOutputStream os = ++ ImageIO.createImageOutputStream(new ByteArrayOutputStream()); ++ writer.setOutput(os); ++ ++ writer.write(getImage()); ++ ++ ++ // NB: dispose() or reset() workarounds the problem. ++ } catch (IOException e) { ++ } finally { ++ writer = null; ++ } ++ count--; ++ } while (count > 0); ++ ++ ++ System.out.println("Wait for GC..."); ++ ++ final long testTimeOut = 60000L; ++ ++ final long startTime = System.currentTimeMillis(); ++ ++ while (!refs.isEmpty()) { ++ // check for the test timeout ++ final long now = System.currentTimeMillis(); ++ ++ if (now - startTime > testTimeOut) { ++ System.out.println(); ++ throw new RuntimeException("Test FAILED."); ++ } ++ ++ System.gc(); ++ ++ try { ++ System.out.print("."); ++ Thread.sleep(1000); ++ } catch (InterruptedException e) { ++ }; ++ ++ Reference r = queue.poll(); ++ if (r != null) { ++ System.out.println("Got reference: " + r); ++ refs.remove(r); ++ } ++ } ++ System.out.println("Test PASSED."); ++ } ++ ++ private static BufferedImage getImage() { ++ int width = 2500; ++ int height = new Random().nextInt(2500) + 1; ++ BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); ++ ++ Graphics2D g = image.createGraphics(); ++ g.setColor(Color.blue); ++ g.fillRect(0, 0, width, height); ++ ++ return image; ++ } ++}