Skip to content

Commit

Permalink
Fix memory leak when checking integrity of certain corrupt JPEG images.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjko committed Jan 8, 2023
1 parent 20f6021 commit afcaf53
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions jpeginfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ int main(int argc, char **argv)

if (!buf || !MD5) no_memory();

for(i = 0; i < BUF_LINES; i++) {
buf[i] = NULL;
}

cinfo.err = jpeg_std_error(&jerr.pub);
jpeg_create_decompress(&cinfo);
jerr.pub.error_exit=my_error_exit;
Expand All @@ -312,6 +316,12 @@ int main(int argc, char **argv)

if (setjmp(jerr.setjmp_buffer)) {
jpeg_abort_decompress(&cinfo);
for(j = 0; j < BUF_LINES; j++) {
if (buf[j]) {
free(buf[j]);
buf[j] = NULL;
}
}
fclose(infile);
if (list_mode && quiet_mode < 2) printf(" %s", current);
if (quiet_mode < 2) printf(" [ERROR]\n");
Expand Down Expand Up @@ -423,7 +433,7 @@ int main(int argc, char **argv)
cinfo.scale_denom = 8;
cinfo.scale_num = 1;
jpeg_start_decompress(&cinfo);

for (j=0;j<BUF_LINES;j++) {
buf[j]=malloc(sizeof(JSAMPLE) *
cinfo.output_width *
Expand All @@ -432,11 +442,14 @@ int main(int argc, char **argv)
}

while (cinfo.output_scanline < cinfo.output_height) {
jpeg_read_scanlines(&cinfo, buf,BUF_LINES);
jpeg_read_scanlines(&cinfo, buf, BUF_LINES);
}

jpeg_finish_decompress(&cinfo);
for(j=0;j<BUF_LINES;j++) free(buf[j]);
for(j = 0; j < BUF_LINES; j++) {
free(buf[j]);
buf[j] = NULL;
}
fclose(infile);

if (!global_error_counter) {
Expand Down

0 comments on commit afcaf53

Please sign in to comment.