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.

65 lines
2.3 KiB

  1. commit 17d56c24c10ed300233164cc51380979124d6dd8
  2. Author: erouault <erouault>
  3. Date: Sat Dec 3 12:19:32 2016 +0000
  4. * tools/tiffcrop.c: add 3 extra bytes at end of strip buffer in
  5. readSeparateStripsIntoBuffer() to avoid read outside of heap allocated buffer.
  6. Reported by Agostino Sarubbo.
  7. Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2621
  8. diff --git a/ChangeLog b/ChangeLog
  9. index d6a416b..50db803 100644
  10. --- a/ChangeLog
  11. +++ b/ChangeLog
  12. @@ -1,5 +1,12 @@
  13. 2016-12-03 Even Rouault <even.rouault at spatialys.com>
  14. + * tools/tiffcrop.c: add 3 extra bytes at end of strip buffer in
  15. + readSeparateStripsIntoBuffer() to avoid read outside of heap allocated buffer.
  16. + Reported by Agostino Sarubbo.
  17. + Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2621
  18. +
  19. +2016-12-03 Even Rouault <even.rouault at spatialys.com>
  20. +
  21. * tools/tiffcrop.c: fix readContigStripsIntoBuffer() in -i (ignore) mode so
  22. that the output buffer is correctly incremented to avoid write outside bounds.
  23. Reported by Agostino Sarubbo.
  24. diff --git a/tools/tiffcrop.c b/tools/tiffcrop.c
  25. index bdcbd63..9122aab 100644
  26. --- a/tools/tiffcrop.c
  27. +++ b/tools/tiffcrop.c
  28. @@ -1,4 +1,4 @@
  29. -/* $Id: tiffcrop.c,v 1.47 2016-12-03 11:35:56 erouault Exp $ */
  30. +/* $Id: tiffcrop.c,v 1.48 2016-12-03 12:19:32 erouault Exp $ */
  31. /* tiffcrop.c -- a port of tiffcp.c extended to include manipulations of
  32. * the image data through additional options listed below
  33. @@ -4815,10 +4815,17 @@ static int readSeparateStripsIntoBuffer (TIFF *in, uint8 *obuf, uint32 length,
  34. nstrips = TIFFNumberOfStrips(in);
  35. strips_per_sample = nstrips /spp;
  36. + /* Add 3 padding bytes for combineSeparateSamples32bits */
  37. + if( (size_t) stripsize > 0xFFFFFFFFU - 3U )
  38. + {
  39. + TIFFError("readSeparateStripsIntoBuffer", "Integer overflow when calculating buffer size.");
  40. + exit(-1);
  41. + }
  42. +
  43. for (s = 0; (s < spp) && (s < MAX_SAMPLES); s++)
  44. {
  45. srcbuffs[s] = NULL;
  46. - buff = _TIFFmalloc(stripsize);
  47. + buff = _TIFFmalloc(stripsize + 3);
  48. if (!buff)
  49. {
  50. TIFFError ("readSeparateStripsIntoBuffer",
  51. @@ -4827,6 +4834,9 @@ static int readSeparateStripsIntoBuffer (TIFF *in, uint8 *obuf, uint32 length,
  52. _TIFFfree (srcbuffs[i]);
  53. return 0;
  54. }
  55. + buff[stripsize] = 0;
  56. + buff[stripsize+1] = 0;
  57. + buff[stripsize+2] = 0;
  58. srcbuffs[s] = buff;
  59. }