Skip to content
This repository has been archived by the owner on Dec 1, 2017. It is now read-only.

Commit

Permalink
* tools/tiff2bw.c: close TIFF handle in error code path.
Browse files Browse the repository at this point in the history
  • Loading branch information
erouault committed Apr 28, 2017
1 parent 62aecad commit 81390ba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
2017-04-28 Even Rouault <even.rouault at spatialys.com>

* tools/tiff2bw.c: close TIFF handle in error code path.
Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2677

2017-04-27 Even Rouault <even.rouault at spatialys.com>

* litiff/tif_fax3.c: avoid crash in Fax3Close() on empty file.
Expand Down
7 changes: 7 additions & 0 deletions tools/tiff2bw.c
Expand Up @@ -165,23 +165,27 @@ main(int argc, char* argv[])
fprintf(stderr,
"%s: Bad photometric; can only handle RGB and Palette images.\n",
argv[optind]);
TIFFClose(in);
return (-1);
}
TIFFGetField(in, TIFFTAG_SAMPLESPERPIXEL, &samplesperpixel);
if (samplesperpixel != 1 && samplesperpixel != 3) {
fprintf(stderr, "%s: Bad samples/pixel %u.\n",
argv[optind], samplesperpixel);
TIFFClose(in);
return (-1);
}
if( photometric == PHOTOMETRIC_RGB && samplesperpixel != 3) {
fprintf(stderr, "%s: Bad samples/pixel %u for PHOTOMETRIC_RGB.\n",
argv[optind], samplesperpixel);
TIFFClose(in);
return (-1);
}
TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bitspersample);
if (bitspersample != 8) {
fprintf(stderr,
" %s: Sorry, only handle 8-bit samples.\n", argv[optind]);
TIFFClose(in);
return (-1);
}
TIFFGetField(in, TIFFTAG_IMAGEWIDTH, &w);
Expand All @@ -190,7 +194,10 @@ main(int argc, char* argv[])

out = TIFFOpen(argv[optind+1], "w");
if (out == NULL)
{
TIFFClose(in);
return (-1);
}
TIFFSetField(out, TIFFTAG_IMAGEWIDTH, w);
TIFFSetField(out, TIFFTAG_IMAGELENGTH, h);
TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8);
Expand Down

0 comments on commit 81390ba

Please sign in to comment.