Skip to content

Commit

Permalink
tjbench.exe: Fix decompression access violation
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
dcommander committed Nov 14, 2017
1 parent 907dd68 commit 5fce2e9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
=====
Expand Down
13 changes: 6 additions & 7 deletions tjbench.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 5fce2e9

Please sign in to comment.