From 5fce2e942136cb70e5a30ff15a2d58b07947aa84 Mon Sep 17 00:00:00 2001 From: DRC Date: Tue, 14 Nov 2017 15:30:06 -0600 Subject: [PATCH] tjbench.exe: Fix decompression access violation The program crashed when a JPEG image was passed on the command line, because we were mixing our metaphors vis-a-vis malloc()/free() and tjAlloc()/tjFree() (malloc()/free() uses the tjbench.exe heap, whereas tjAlloc()/tjFree() uses the turbojpeg.dll heap.) --- ChangeLog.md | 3 +++ tjbench.c | 13 ++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index e6565cd14..7aa507e75 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -25,6 +25,9 @@ quantization was enabled. command-line argument is unrecognized. This prevents the program from silently ignoring typos. +6. Fixed an access violation in tjbench.exe (Windows) that occurred when the +program was used to decompress an existing JPEG image. + 1.5.2 ===== diff --git a/tjbench.c b/tjbench.c index dfe66019a..76b61cdf2 100644 --- a/tjbench.c +++ b/tjbench.c @@ -502,7 +502,7 @@ int decompTest(char *filename) char *temp=NULL, tempstr[80], tempstr2[80]; int row, col, i, iter, tilew, tileh, ntilesw=1, ntilesh=1, retval=0; double start, elapsed; - int ps=tjPixelSize[pf], tile; + int ps=tjPixelSize[pf], tile, decompsrc=0; if((file=fopen(filename, "rb"))==NULL) _throwunix("opening file"); @@ -682,18 +682,17 @@ int decompTest(char *filename) else { if(quiet==1) printf("N/A N/A "); - jpegsize[0]=srcsize; - free(jpegbuf[0]); - jpegbuf[0]=srcbuf; - srcbuf=NULL; + tjFree(jpegbuf[0]); + jpegbuf[0]=NULL; + decompsrc=1; } if(w==tilew) _tilew=_w; if(h==tileh) _tileh=_h; if(!(xformopt&TJXOPT_NOOUTPUT)) { - if(decomp(NULL, jpegbuf, jpegsize, NULL, _w, _h, _subsamp, 0, - filename, _tilew, _tileh)==-1) + if(decomp(NULL, decompsrc? &srcbuf:jpegbuf, decompsrc? &srcsize:jpegsize, + NULL, _w, _h, _subsamp, 0, filename, _tilew, _tileh)==-1) goto bailout; } else if(quiet==1) printf("N/A\n");