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.

209 lines
7.0 KiB

  1. commit 40448d58fbfad52d2dde5bd18daa30b17fe35fcd
  2. Author: erouault <erouault>
  3. Date: Thu Jun 1 12:44:04 2017 +0000
  4. * libtiff/tif_dirinfo.c, tif_dirread.c: add _TIFFCheckFieldIsValidForCodec(),
  5. and use it in TIFFReadDirectory() so as to ignore fields whose tag is a
  6. codec-specified tag but this codec is not enabled. This avoids TIFFGetField()
  7. to behave differently depending on whether the codec is enabled or not, and
  8. thus can avoid stack based buffer overflows in a number of TIFF utilities
  9. such as tiffsplit, tiffcmp, thumbnail, etc.
  10. Patch derived from 0063-Handle-properly-CODEC-specific-tags.patch
  11. (http://bugzilla.maptools.org/show_bug.cgi?id=2580) by Raphaël Hertzog.
  12. Fixes:
  13. http://bugzilla.maptools.org/show_bug.cgi?id=2580
  14. http://bugzilla.maptools.org/show_bug.cgi?id=2693
  15. http://bugzilla.maptools.org/show_bug.cgi?id=2625 (CVE-2016-10095)
  16. http://bugzilla.maptools.org/show_bug.cgi?id=2564 (CVE-2015-7554)
  17. http://bugzilla.maptools.org/show_bug.cgi?id=2561 (CVE-2016-5318)
  18. http://bugzilla.maptools.org/show_bug.cgi?id=2499 (CVE-2014-8128)
  19. http://bugzilla.maptools.org/show_bug.cgi?id=2441
  20. http://bugzilla.maptools.org/show_bug.cgi?id=2433
  21. diff --git a/ChangeLog b/ChangeLog
  22. index 04881ba7..ebd1a3c0 100644
  23. --- a/ChangeLog
  24. +++ b/ChangeLog
  25. @@ -1,3 +1,23 @@
  26. +2017-06-01 Even Rouault <even.rouault at spatialys.com>
  27. +
  28. + * libtiff/tif_dirinfo.c, tif_dirread.c: add _TIFFCheckFieldIsValidForCodec(),
  29. + and use it in TIFFReadDirectory() so as to ignore fields whose tag is a
  30. + codec-specified tag but this codec is not enabled. This avoids TIFFGetField()
  31. + to behave differently depending on whether the codec is enabled or not, and
  32. + thus can avoid stack based buffer overflows in a number of TIFF utilities
  33. + such as tiffsplit, tiffcmp, thumbnail, etc.
  34. + Patch derived from 0063-Handle-properly-CODEC-specific-tags.patch
  35. + (http://bugzilla.maptools.org/show_bug.cgi?id=2580) by Raphaël Hertzog.
  36. + Fixes:
  37. + http://bugzilla.maptools.org/show_bug.cgi?id=2580
  38. + http://bugzilla.maptools.org/show_bug.cgi?id=2693
  39. + http://bugzilla.maptools.org/show_bug.cgi?id=2625 (CVE-2016-10095)
  40. + http://bugzilla.maptools.org/show_bug.cgi?id=2564 (CVE-2015-7554)
  41. + http://bugzilla.maptools.org/show_bug.cgi?id=2561 (CVE-2016-5318)
  42. + http://bugzilla.maptools.org/show_bug.cgi?id=2499 (CVE-2014-8128)
  43. + http://bugzilla.maptools.org/show_bug.cgi?id=2441
  44. + http://bugzilla.maptools.org/show_bug.cgi?id=2433
  45. +
  46. 2017-05-29 Even Rouault <even.rouault at spatialys.com>
  47. * libtiff/tif_getimage.c: initYCbCrConversion(): stricter validation for
  48. diff --git a/libtiff/tif_dir.h b/libtiff/tif_dir.h
  49. index 6af5f3dc..5a380767 100644
  50. --- a/libtiff/tif_dir.h
  51. +++ b/libtiff/tif_dir.h
  52. @@ -1,4 +1,4 @@
  53. -/* $Id: tif_dir.h,v 1.54 2011-02-18 20:53:05 fwarmerdam Exp $ */
  54. +/* $Id: tif_dir.h,v 1.55 2017-06-01 12:44:04 erouault Exp $ */
  55. /*
  56. * Copyright (c) 1988-1997 Sam Leffler
  57. @@ -291,6 +291,7 @@ struct _TIFFField {
  58. extern int _TIFFMergeFields(TIFF*, const TIFFField[], uint32);
  59. extern const TIFFField* _TIFFFindOrRegisterField(TIFF *, uint32, TIFFDataType);
  60. extern TIFFField* _TIFFCreateAnonField(TIFF *, uint32, TIFFDataType);
  61. +extern int _TIFFCheckFieldIsValidForCodec(TIFF *tif, ttag_t tag);
  62. #if defined(__cplusplus)
  63. }
  64. diff --git a/libtiff/tif_dirinfo.c b/libtiff/tif_dirinfo.c
  65. index 23ad0020..4904f540 100644
  66. --- a/libtiff/tif_dirinfo.c
  67. +++ b/libtiff/tif_dirinfo.c
  68. @@ -1,4 +1,4 @@
  69. -/* $Id: tif_dirinfo.c,v 1.126 2016-11-18 02:52:13 bfriesen Exp $ */
  70. +/* $Id: tif_dirinfo.c,v 1.127 2017-06-01 12:44:04 erouault Exp $ */
  71. /*
  72. * Copyright (c) 1988-1997 Sam Leffler
  73. @@ -956,6 +956,109 @@ TIFFMergeFieldInfo(TIFF* tif, const TIFFFieldInfo info[], uint32 n)
  74. return 0;
  75. }
  76. +int
  77. +_TIFFCheckFieldIsValidForCodec(TIFF *tif, ttag_t tag)
  78. +{
  79. + /* Filter out non-codec specific tags */
  80. + switch (tag) {
  81. + /* Shared tags */
  82. + case TIFFTAG_PREDICTOR:
  83. + /* JPEG tags */
  84. + case TIFFTAG_JPEGTABLES:
  85. + /* OJPEG tags */
  86. + case TIFFTAG_JPEGIFOFFSET:
  87. + case TIFFTAG_JPEGIFBYTECOUNT:
  88. + case TIFFTAG_JPEGQTABLES:
  89. + case TIFFTAG_JPEGDCTABLES:
  90. + case TIFFTAG_JPEGACTABLES:
  91. + case TIFFTAG_JPEGPROC:
  92. + case TIFFTAG_JPEGRESTARTINTERVAL:
  93. + /* CCITT* */
  94. + case TIFFTAG_BADFAXLINES:
  95. + case TIFFTAG_CLEANFAXDATA:
  96. + case TIFFTAG_CONSECUTIVEBADFAXLINES:
  97. + case TIFFTAG_GROUP3OPTIONS:
  98. + case TIFFTAG_GROUP4OPTIONS:
  99. + break;
  100. + default:
  101. + return 1;
  102. + }
  103. + /* Check if codec specific tags are allowed for the current
  104. + * compression scheme (codec) */
  105. + switch (tif->tif_dir.td_compression) {
  106. + case COMPRESSION_LZW:
  107. + if (tag == TIFFTAG_PREDICTOR)
  108. + return 1;
  109. + break;
  110. + case COMPRESSION_PACKBITS:
  111. + /* No codec-specific tags */
  112. + break;
  113. + case COMPRESSION_THUNDERSCAN:
  114. + /* No codec-specific tags */
  115. + break;
  116. + case COMPRESSION_NEXT:
  117. + /* No codec-specific tags */
  118. + break;
  119. + case COMPRESSION_JPEG:
  120. + if (tag == TIFFTAG_JPEGTABLES)
  121. + return 1;
  122. + break;
  123. + case COMPRESSION_OJPEG:
  124. + switch (tag) {
  125. + case TIFFTAG_JPEGIFOFFSET:
  126. + case TIFFTAG_JPEGIFBYTECOUNT:
  127. + case TIFFTAG_JPEGQTABLES:
  128. + case TIFFTAG_JPEGDCTABLES:
  129. + case TIFFTAG_JPEGACTABLES:
  130. + case TIFFTAG_JPEGPROC:
  131. + case TIFFTAG_JPEGRESTARTINTERVAL:
  132. + return 1;
  133. + }
  134. + break;
  135. + case COMPRESSION_CCITTRLE:
  136. + case COMPRESSION_CCITTRLEW:
  137. + case COMPRESSION_CCITTFAX3:
  138. + case COMPRESSION_CCITTFAX4:
  139. + switch (tag) {
  140. + case TIFFTAG_BADFAXLINES:
  141. + case TIFFTAG_CLEANFAXDATA:
  142. + case TIFFTAG_CONSECUTIVEBADFAXLINES:
  143. + return 1;
  144. + case TIFFTAG_GROUP3OPTIONS:
  145. + if (tif->tif_dir.td_compression == COMPRESSION_CCITTFAX3)
  146. + return 1;
  147. + break;
  148. + case TIFFTAG_GROUP4OPTIONS:
  149. + if (tif->tif_dir.td_compression == COMPRESSION_CCITTFAX4)
  150. + return 1;
  151. + break;
  152. + }
  153. + break;
  154. + case COMPRESSION_JBIG:
  155. + /* No codec-specific tags */
  156. + break;
  157. + case COMPRESSION_DEFLATE:
  158. + case COMPRESSION_ADOBE_DEFLATE:
  159. + if (tag == TIFFTAG_PREDICTOR)
  160. + return 1;
  161. + break;
  162. + case COMPRESSION_PIXARLOG:
  163. + if (tag == TIFFTAG_PREDICTOR)
  164. + return 1;
  165. + break;
  166. + case COMPRESSION_SGILOG:
  167. + case COMPRESSION_SGILOG24:
  168. + /* No codec-specific tags */
  169. + break;
  170. + case COMPRESSION_LZMA:
  171. + if (tag == TIFFTAG_PREDICTOR)
  172. + return 1;
  173. + break;
  174. +
  175. + }
  176. + return 0;
  177. +}
  178. +
  179. /* vim: set ts=8 sts=8 sw=8 noet: */
  180. /*
  181. diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c
  182. index 772ebaf7..acde78b5 100644
  183. --- a/libtiff/tif_dirread.c
  184. +++ b/libtiff/tif_dirread.c
  185. @@ -1,4 +1,4 @@
  186. -/* $Id: tif_dirread.c,v 1.208 2017-04-27 15:46:22 erouault Exp $ */
  187. +/* $Id: tif_dirread.c,v 1.209 2017-06-01 12:44:04 erouault Exp $ */
  188. /*
  189. * Copyright (c) 1988-1997 Sam Leffler
  190. @@ -3580,6 +3580,10 @@ TIFFReadDirectory(TIFF* tif)
  191. goto bad;
  192. dp->tdir_tag=IGNORE;
  193. break;
  194. + default:
  195. + if( !_TIFFCheckFieldIsValidForCodec(tif, dp->tdir_tag) )
  196. + dp->tdir_tag=IGNORE;
  197. + break;
  198. }
  199. }
  200. }