From: DRC Date: Sun, 20 Apr 2014 09:42:49 +0000 (+0000) Subject: Fix crashes and bogus output in the CMYK and decode-to-YUV features that occurred... X-Git-Tag: 1.3.90~89 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=230d09dbed4b7f2dfb52b9009770b2979b2aeb8f;p=libjpeg-turbo Fix crashes and bogus output in the CMYK and decode-to-YUV features that occurred if JCS_EXTENSIONS wasn't defined. git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@1260 632fc199-4ca6-4c93-a231-07263d6284db --- diff --git a/turbojpeg.c b/turbojpeg.c index c824132..5ce1594 100644 --- a/turbojpeg.c +++ b/turbojpeg.c @@ -634,7 +634,7 @@ DLLEXPORT int DLLCALL tjCompress2(tjhandle handle, unsigned char *srcBuf, if(pitch==0) pitch=width*tjPixelSize[pixelFormat]; #ifndef JCS_EXTENSIONS - if(pixelFormat!=TJPF_GRAY) + if(pixelFormat!=TJPF_GRAY && pixelFormat!=TJPF_CMYK) { rgbBuf=(unsigned char *)malloc(width*height*RGB_PIXELSIZE); if(!rgbBuf) _throw("tjCompress2(): Memory allocation failure"); @@ -749,7 +749,7 @@ DLLEXPORT int DLLCALL tjEncodeYUV3(tjhandle handle, unsigned char *srcBuf, if(pitch==0) pitch=width*tjPixelSize[pixelFormat]; #ifndef JCS_EXTENSIONS - if(pixelFormat!=TJPF_GRAY) + if(pixelFormat!=TJPF_GRAY && pixelFormat!=TJPF_CMYK) { rgbBuf=(unsigned char *)malloc(width*height*RGB_PIXELSIZE); if(!rgbBuf) _throw("tjEncodeYUV3(): Memory allocation failure"); @@ -1189,7 +1189,7 @@ DLLEXPORT int DLLCALL tjDecompress2(tjhandle handle, unsigned char *jpegBuf, if(pitch==0) pitch=dinfo->output_width*tjPixelSize[pixelFormat]; #ifndef JCS_EXTENSIONS - if(pixelFormat!=TJPF_GRAY && + if(pixelFormat!=TJPF_GRAY && pixelFormat!=TJPF_CMYK && (RGB_RED!=tjRedOffset[pixelFormat] || RGB_GREEN!=tjGreenOffset[pixelFormat] || RGB_BLUE!=tjBlueOffset[pixelFormat] || @@ -1309,6 +1309,7 @@ DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, unsigned char *srcBuf, jpeg_component_info *compptr; #ifndef JCS_EXTENSIONS unsigned char *rgbBuf=NULL; + unsigned char *_dstBuf=NULL; int _pitch=0; #endif JMETHOD(int, old_read_markers, (j_decompress_ptr)); JMETHOD(void, old_reset_marker_reader, (j_decompress_ptr)); @@ -1339,17 +1340,6 @@ DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, unsigned char *srcBuf, _throw("tjDecodeYUV(): Cannot decode YUV images into CMYK pixels."); if(pitch==0) pitch=width*tjPixelSize[pixelFormat]; - - #ifndef JCS_EXTENSIONS - if(pixelFormat!=TJPF_GRAY) - { - rgbBuf=(unsigned char *)malloc(width*height*RGB_PIXELSIZE); - if(!rgbBuf) _throw("tjDecodeYUV(): Memory allocation failure"); - srcBuf=toRGB(srcBuf, width, pitch, height, pixelFormat, rgbBuf); - pitch=width*RGB_PIXELSIZE; - } - #endif - dinfo->image_width=width; dinfo->image_height=height; @@ -1383,6 +1373,20 @@ DLLEXPORT int DLLCALL tjDecodeYUV(tjhandle handle, unsigned char *srcBuf, if(pitch==0) pitch=dinfo->output_width*tjPixelSize[pixelFormat]; + #ifndef JCS_EXTENSIONS + if(pixelFormat!=TJPF_GRAY && pixelFormat!=TJPF_CMYK && + (RGB_RED!=tjRedOffset[pixelFormat] || + RGB_GREEN!=tjGreenOffset[pixelFormat] || + RGB_BLUE!=tjBlueOffset[pixelFormat] || + RGB_PIXELSIZE!=tjPixelSize[pixelFormat])) + { + rgbBuf=(unsigned char *)malloc(width*height*3); + if(!rgbBuf) _throw("tjDecodeYUV(): Memory allocation failure"); + _pitch=pitch; pitch=width*3; + _dstBuf=dstBuf; dstBuf=rgbBuf; + } + #endif + if((row_pointer=(JSAMPROW *)malloc(sizeof(JSAMPROW)*ph))==NULL) _throw("tjDecodeYUV(): Memory allocation failure"); for(i=0; iglobal_state>DSTATE_START) jpeg_abort_decompress(dinfo); #ifndef JCS_EXTENSIONS