Mercurial > hg > release > icedtea6-1.11
view patches/imageiojpeg_sync.patch @ 2929:222321136c48
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 <gnu.andrew@redhat.com>
* 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.
author | Andrew John Hughes <gnu.andrew@redhat.com> |
---|---|
date | Tue, 03 Sep 2013 20:08:26 +0100 |
parents | |
children |
line wrap: on
line 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 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;