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.

135 lines
5.3 KiB

  1. commit c533d200ecc45e00892a94f9bb2e762a5aa0b2ce
  2. Author: erouault <erouault>
  3. Date: Sat Dec 3 11:02:15 2016 +0000
  4. * libtiff/tif_dirread.c: modify ChopUpSingleUncompressedStrip() to
  5. instanciate compute ntrips as TIFFhowmany_32(td->td_imagelength, rowsperstrip),
  6. instead of a logic based on the total size of data. Which is faulty is
  7. the total size of data is not sufficient to fill the whole image, and thus
  8. results in reading outside of the StripByCounts/StripOffsets arrays when
  9. using TIFFReadScanline().
  10. Reported by Agostino Sarubbo.
  11. Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2608.
  12. * libtiff/tif_strip.c: revert the change in TIFFNumberOfStrips() done
  13. for http://bugzilla.maptools.org/show_bug.cgi?id=2587 / CVE-2016-9273 since
  14. the above change is a better fix that makes it unnecessary.
  15. diff --git a/ChangeLog b/ChangeLog
  16. index 93c01f8..9dbc7a0 100644
  17. --- a/ChangeLog
  18. +++ b/ChangeLog
  19. @@ -1,5 +1,20 @@
  20. 2016-12-03 Even Rouault <even.rouault at spatialys.com>
  21. + * libtiff/tif_dirread.c: modify ChopUpSingleUncompressedStrip() to
  22. + instanciate compute ntrips as TIFFhowmany_32(td->td_imagelength, rowsperstrip),
  23. + instead of a logic based on the total size of data. Which is faulty is
  24. + the total size of data is not sufficient to fill the whole image, and thus
  25. + results in reading outside of the StripByCounts/StripOffsets arrays when
  26. + using TIFFReadScanline().
  27. + Reported by Agostino Sarubbo.
  28. + Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2608.
  29. +
  30. + * libtiff/tif_strip.c: revert the change in TIFFNumberOfStrips() done
  31. + for http://bugzilla.maptools.org/show_bug.cgi?id=2587 / CVE-2016-9273 since
  32. + the above change is a better fix that makes it unnecessary.
  33. +
  34. +2016-12-03 Even Rouault <even.rouault at spatialys.com>
  35. +
  36. * libtiff/tif_pixarlog.c, libtiff/tif_luv.c: fix heap-based buffer
  37. overflow on generation of PixarLog / LUV compressed files, with
  38. ColorMap, TransferFunction attached and nasty plays with bitspersample.
  39. diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c
  40. index 01070f2..f290528 100644
  41. --- a/libtiff/tif_dirread.c
  42. +++ b/libtiff/tif_dirread.c
  43. @@ -1,4 +1,4 @@
  44. -/* $Id: tif_dirread.c,v 1.204 2016-11-16 15:14:15 erouault Exp $ */
  45. +/* $Id: tif_dirread.c,v 1.205 2016-12-03 11:02:15 erouault Exp $ */
  46. /*
  47. * Copyright (c) 1988-1997 Sam Leffler
  48. @@ -5502,8 +5502,7 @@ ChopUpSingleUncompressedStrip(TIFF* tif)
  49. uint64 rowblockbytes;
  50. uint64 stripbytes;
  51. uint32 strip;
  52. - uint64 nstrips64;
  53. - uint32 nstrips32;
  54. + uint32 nstrips;
  55. uint32 rowsperstrip;
  56. uint64* newcounts;
  57. uint64* newoffsets;
  58. @@ -5534,18 +5533,17 @@ ChopUpSingleUncompressedStrip(TIFF* tif)
  59. return;
  60. /*
  61. - * never increase the number of strips in an image
  62. + * never increase the number of rows per strip
  63. */
  64. if (rowsperstrip >= td->td_rowsperstrip)
  65. return;
  66. - nstrips64 = TIFFhowmany_64(bytecount, stripbytes);
  67. - if ((nstrips64==0)||(nstrips64>0xFFFFFFFF)) /* something is wonky, do nothing. */
  68. - return;
  69. - nstrips32 = (uint32)nstrips64;
  70. + nstrips = TIFFhowmany_32(td->td_imagelength, rowsperstrip);
  71. + if( nstrips == 0 )
  72. + return;
  73. - newcounts = (uint64*) _TIFFCheckMalloc(tif, nstrips32, sizeof (uint64),
  74. + newcounts = (uint64*) _TIFFCheckMalloc(tif, nstrips, sizeof (uint64),
  75. "for chopped \"StripByteCounts\" array");
  76. - newoffsets = (uint64*) _TIFFCheckMalloc(tif, nstrips32, sizeof (uint64),
  77. + newoffsets = (uint64*) _TIFFCheckMalloc(tif, nstrips, sizeof (uint64),
  78. "for chopped \"StripOffsets\" array");
  79. if (newcounts == NULL || newoffsets == NULL) {
  80. /*
  81. @@ -5562,18 +5560,18 @@ ChopUpSingleUncompressedStrip(TIFF* tif)
  82. * Fill the strip information arrays with new bytecounts and offsets
  83. * that reflect the broken-up format.
  84. */
  85. - for (strip = 0; strip < nstrips32; strip++) {
  86. + for (strip = 0; strip < nstrips; strip++) {
  87. if (stripbytes > bytecount)
  88. stripbytes = bytecount;
  89. newcounts[strip] = stripbytes;
  90. - newoffsets[strip] = offset;
  91. + newoffsets[strip] = stripbytes ? offset : 0;
  92. offset += stripbytes;
  93. bytecount -= stripbytes;
  94. }
  95. /*
  96. * Replace old single strip info with multi-strip info.
  97. */
  98. - td->td_stripsperimage = td->td_nstrips = nstrips32;
  99. + td->td_stripsperimage = td->td_nstrips = nstrips;
  100. TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, rowsperstrip);
  101. _TIFFfree(td->td_stripbytecount);
  102. diff --git a/libtiff/tif_strip.c b/libtiff/tif_strip.c
  103. index b6098dd..6e9f2ef 100644
  104. --- a/libtiff/tif_strip.c
  105. +++ b/libtiff/tif_strip.c
  106. @@ -1,4 +1,4 @@
  107. -/* $Id: tif_strip.c,v 1.37 2016-11-09 23:00:49 erouault Exp $ */
  108. +/* $Id: tif_strip.c,v 1.38 2016-12-03 11:02:15 erouault Exp $ */
  109. /*
  110. * Copyright (c) 1991-1997 Sam Leffler
  111. @@ -63,15 +63,6 @@ TIFFNumberOfStrips(TIFF* tif)
  112. TIFFDirectory *td = &tif->tif_dir;
  113. uint32 nstrips;
  114. - /* If the value was already computed and store in td_nstrips, then return it,
  115. - since ChopUpSingleUncompressedStrip might have altered and resized the
  116. - since the td_stripbytecount and td_stripoffset arrays to the new value
  117. - after the initial affectation of td_nstrips = TIFFNumberOfStrips() in
  118. - tif_dirread.c ~line 3612.
  119. - See http://bugzilla.maptools.org/show_bug.cgi?id=2587 */
  120. - if( td->td_nstrips )
  121. - return td->td_nstrips;
  122. -
  123. nstrips = (td->td_rowsperstrip == (uint32) -1 ? 1 :
  124. TIFFhowmany_32(td->td_imagelength, td->td_rowsperstrip));
  125. if (td->td_planarconfig == PLANARCONFIG_SEPARATE)