You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.4 KiB

  1. commit fc9eedf265394eb8a5633160a8fcdb7ece072701
  2. Author: erouault <erouault>
  3. Date: Sat Dec 3 13:00:03 2016 +0000
  4. * tools/tiffcrop.c: fix integer division by zero when BitsPerSample is missing.
  5. Reported by Agostino Sarubbo.
  6. Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2619
  7. diff --git a/ChangeLog b/ChangeLog
  8. index 50db803..2940828 100644
  9. --- a/ChangeLog
  10. +++ b/ChangeLog
  11. @@ -1,5 +1,11 @@
  12. 2016-12-03 Even Rouault <even.rouault at spatialys.com>
  13. + * tools/tiffcrop.c: fix integer division by zero when BitsPerSample is missing.
  14. + Reported by Agostino Sarubbo.
  15. + Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2619
  16. +
  17. +2016-12-03 Even Rouault <even.rouault at spatialys.com>
  18. +
  19. * tools/tiffcrop.c: add 3 extra bytes at end of strip buffer in
  20. readSeparateStripsIntoBuffer() to avoid read outside of heap allocated buffer.
  21. Reported by Agostino Sarubbo.
  22. diff --git a/tools/tiffcrop.c b/tools/tiffcrop.c
  23. index 9122aab..21dd087 100644
  24. --- a/tools/tiffcrop.c
  25. +++ b/tools/tiffcrop.c
  26. @@ -1,4 +1,4 @@
  27. -/* $Id: tiffcrop.c,v 1.48 2016-12-03 12:19:32 erouault Exp $ */
  28. +/* $Id: tiffcrop.c,v 1.49 2016-12-03 13:00:04 erouault Exp $ */
  29. /* tiffcrop.c -- a port of tiffcp.c extended to include manipulations of
  30. * the image data through additional options listed below
  31. @@ -1164,7 +1164,7 @@ writeBufferToSeparateStrips (TIFF* out, uint8* buf,
  32. tdata_t obuf;
  33. (void) TIFFGetFieldDefaulted(out, TIFFTAG_ROWSPERSTRIP, &rowsperstrip);
  34. - (void) TIFFGetField(out, TIFFTAG_BITSPERSAMPLE, &bps);
  35. + (void) TIFFGetFieldDefaulted(out, TIFFTAG_BITSPERSAMPLE, &bps);
  36. bytes_per_sample = (bps + 7) / 8;
  37. if( width == 0 ||
  38. (uint32)bps * (uint32)spp > TIFF_UINT32_MAX / width ||
  39. @@ -4760,7 +4760,7 @@ static int readSeparateStripsIntoBuffer (TIFF *in, uint8 *obuf, uint32 length,
  40. int i, bytes_per_sample, bytes_per_pixel, shift_width, result = 1;
  41. uint32 j;
  42. int32 bytes_read = 0;
  43. - uint16 bps, planar;
  44. + uint16 bps = 0, planar;
  45. uint32 nstrips;
  46. uint32 strips_per_sample;
  47. uint32 src_rowsize, dst_rowsize, rows_processed, rps;
  48. @@ -4780,7 +4780,7 @@ static int readSeparateStripsIntoBuffer (TIFF *in, uint8 *obuf, uint32 length,
  49. }
  50. memset (srcbuffs, '\0', sizeof(srcbuffs));
  51. - TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bps);
  52. + TIFFGetFieldDefaulted(in, TIFFTAG_BITSPERSAMPLE, &bps);
  53. TIFFGetFieldDefaulted(in, TIFFTAG_PLANARCONFIG, &planar);
  54. TIFFGetFieldDefaulted(in, TIFFTAG_ROWSPERSTRIP, &rps);
  55. if (rps > length)