]> granicus.if.org Git - libjpeg-turbo/commitdiff
tjbench.exe: Fix decompression access violation
authorDRC <information@libjpeg-turbo.org>
Tue, 14 Nov 2017 21:30:06 +0000 (15:30 -0600)
committerDRC <information@libjpeg-turbo.org>
Tue, 14 Nov 2017 21:41:30 +0000 (15:41 -0600)
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
tjbench.c

index e6565cd144a399929a46150475e4158a9fd14816..7aa507e758862affed811179238f276875c030fc 100644 (file)
@@ -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
 =====
index dfe66019ac2a4397ef87e53030fd904bbd237a50..76b61cdf2fe22f0944da145d9edd116f70920f09 100644 (file)
--- 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");