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.

84 lines
2.9 KiB

  1. From 5c080298d59efa53264d7248bbe3a04660db6ef7 Mon Sep 17 00:00:00 2001
  2. From: erouault <erouault>
  3. Date: Wed, 11 Jan 2017 19:25:44 +0000
  4. Subject: [PATCH] * tools/tiffcp.c: error out cleanly in cpContig2SeparateByRow
  5. and cpSeparate2ContigByRow if BitsPerSample != 8 to avoid heap based
  6. overflow. Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2656 and
  7. http://bugzilla.maptools.org/show_bug.cgi?id=2657
  8. ---
  9. ChangeLog | 7 +++++++
  10. tools/tiffcp.c | 24 ++++++++++++++++++++++--
  11. 2 files changed, 29 insertions(+), 2 deletions(-)
  12. diff --git a/ChangeLog b/ChangeLog
  13. index f78cad0..064f25b 100644
  14. --- a/ChangeLog
  15. +++ b/ChangeLog
  16. @@ -1,3 +1,10 @@
  17. +2017-01-11 Even Rouault <even.rouault at spatialys.com>
  18. +
  19. + * tools/tiffcp.c: error out cleanly in cpContig2SeparateByRow and
  20. + cpSeparate2ContigByRow if BitsPerSample != 8 to avoid heap based overflow.
  21. + Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2656 and
  22. + http://bugzilla.maptools.org/show_bug.cgi?id=2657
  23. +
  24. 2016-12-20 Even Rouault <even.rouault at spatialys.com>
  25. * tools/tiff2pdf.c: avoid potential heap-based overflow in
  26. diff --git a/tools/tiffcp.c b/tools/tiffcp.c
  27. index bdf754c..8bbcd52 100644
  28. --- a/tools/tiffcp.c
  29. +++ b/tools/tiffcp.c
  30. @@ -591,7 +591,7 @@ static copyFunc pickCopyFunc(TIFF*, TIFF*, uint16, uint16);
  31. static int
  32. tiffcp(TIFF* in, TIFF* out)
  33. {
  34. - uint16 bitspersample, samplesperpixel = 1;
  35. + uint16 bitspersample = 1, samplesperpixel = 1;
  36. uint16 input_compression, input_photometric = PHOTOMETRIC_MINISBLACK;
  37. copyFunc cf;
  38. uint32 width, length;
  39. @@ -1067,6 +1067,16 @@ DECLAREcpFunc(cpContig2SeparateByRow)
  40. register uint32 n;
  41. uint32 row;
  42. tsample_t s;
  43. + uint16 bps = 0;
  44. +
  45. + (void) TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bps);
  46. + if( bps != 8 )
  47. + {
  48. + TIFFError(TIFFFileName(in),
  49. + "Error, can only handle BitsPerSample=8 in %s",
  50. + "cpContig2SeparateByRow");
  51. + return 0;
  52. + }
  53. inbuf = _TIFFmalloc(scanlinesizein);
  54. outbuf = _TIFFmalloc(scanlinesizeout);
  55. @@ -1120,6 +1130,16 @@ DECLAREcpFunc(cpSeparate2ContigByRow)
  56. register uint32 n;
  57. uint32 row;
  58. tsample_t s;
  59. + uint16 bps = 0;
  60. +
  61. + (void) TIFFGetField(in, TIFFTAG_BITSPERSAMPLE, &bps);
  62. + if( bps != 8 )
  63. + {
  64. + TIFFError(TIFFFileName(in),
  65. + "Error, can only handle BitsPerSample=8 in %s",
  66. + "cpSeparate2ContigByRow");
  67. + return 0;
  68. + }
  69. inbuf = _TIFFmalloc(scanlinesizein);
  70. outbuf = _TIFFmalloc(scanlinesizeout);
  71. @@ -1784,7 +1804,7 @@ pickCopyFunc(TIFF* in, TIFF* out, uint16 bitspersample, uint16 samplesperpixel)
  72. uint32 w, l, tw, tl;
  73. int bychunk;
  74. - (void) TIFFGetField(in, TIFFTAG_PLANARCONFIG, &shortv);
  75. + (void) TIFFGetFieldDefaulted(in, TIFFTAG_PLANARCONFIG, &shortv);
  76. if (shortv != config && bitspersample != 8 && samplesperpixel > 1) {
  77. fprintf(stderr,
  78. "%s: Cannot handle different planar configuration w/ bits/sample != 8\n",