patch-libtiff_tif_getimage_c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. $OpenBSD: patch-libtiff_tif_getimage_c,v 1.12 2017/05/26 20:50:57 naddy Exp $
  2. This one is slightly problematic. If an application allocates less
  3. room for its error buffer than the recommended 1024, the error message
  4. buffer will still overflow.
  5. Index: libtiff/tif_getimage.c
  6. --- libtiff/tif_getimage.c.orig
  7. +++ libtiff/tif_getimage.c
  8. @@ -80,7 +80,7 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024])
  9. int colorchannels;
  10. if (!tif->tif_decodestatus) {
  11. - sprintf(emsg, "Sorry, requested compression method is not configured");
  12. + snprintf(emsg, 1024, "Sorry, requested compression method is not configured");
  13. return (0);
  14. }
  15. switch (td->td_bitspersample) {
  16. @@ -91,12 +91,12 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024])
  17. case 16:
  18. break;
  19. default:
  20. - sprintf(emsg, "Sorry, can not handle images with %d-bit samples",
  21. + snprintf(emsg, 1024, "Sorry, can not handle images with %d-bit samples",
  22. td->td_bitspersample);
  23. return (0);
  24. }
  25. if (td->td_sampleformat == SAMPLEFORMAT_IEEEFP) {
  26. - sprintf(emsg, "Sorry, can not handle images with IEEE floating-point samples");
  27. + snprintf(emsg, 1024, "Sorry, can not handle images with IEEE floating-point samples");
  28. return (0);
  29. }
  30. colorchannels = td->td_samplesperpixel - td->td_extrasamples;
  31. @@ -109,7 +109,7 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024])
  32. photometric = PHOTOMETRIC_RGB;
  33. break;
  34. default:
  35. - sprintf(emsg, "Missing needed %s tag", photoTag);
  36. + snprintf(emsg, 1024, "Missing needed %s tag", photoTag);
  37. return (0);
  38. }
  39. }
  40. @@ -120,7 +120,7 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024])
  41. if (td->td_planarconfig == PLANARCONFIG_CONTIG
  42. && td->td_samplesperpixel != 1
  43. && td->td_bitspersample < 8 ) {
  44. - sprintf(emsg,
  45. + snprintf(emsg, 1024,
  46. "Sorry, can not handle contiguous data with %s=%d, "
  47. "and %s=%d and Bits/Sample=%d",
  48. photoTag, photometric,
  49. @@ -144,7 +144,7 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024])
  50. break;
  51. case PHOTOMETRIC_RGB:
  52. if (colorchannels < 3) {
  53. - sprintf(emsg, "Sorry, can not handle RGB image with %s=%d",
  54. + snprintf(emsg, 1024, "Sorry, can not handle RGB image with %s=%d",
  55. "Color channels", colorchannels);
  56. return (0);
  57. }
  58. @@ -154,13 +154,13 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024])
  59. uint16 inkset;
  60. TIFFGetFieldDefaulted(tif, TIFFTAG_INKSET, &inkset);
  61. if (inkset != INKSET_CMYK) {
  62. - sprintf(emsg,
  63. + snprintf(emsg, 1024,
  64. "Sorry, can not handle separated image with %s=%d",
  65. "InkSet", inkset);
  66. return 0;
  67. }
  68. if (td->td_samplesperpixel < 4) {
  69. - sprintf(emsg,
  70. + snprintf(emsg, 1024,
  71. "Sorry, can not handle separated image with %s=%d",
  72. "Samples/pixel", td->td_samplesperpixel);
  73. return 0;
  74. @@ -169,7 +169,7 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024])
  75. }
  76. case PHOTOMETRIC_LOGL:
  77. if (td->td_compression != COMPRESSION_SGILOG) {
  78. - sprintf(emsg, "Sorry, LogL data must have %s=%d",
  79. + snprintf(emsg, 1024, "Sorry, LogL data must have %s=%d",
  80. "Compression", COMPRESSION_SGILOG);
  81. return (0);
  82. }
  83. @@ -177,17 +177,17 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024])
  84. case PHOTOMETRIC_LOGLUV:
  85. if (td->td_compression != COMPRESSION_SGILOG &&
  86. td->td_compression != COMPRESSION_SGILOG24) {
  87. - sprintf(emsg, "Sorry, LogLuv data must have %s=%d or %d",
  88. + snprintf(emsg, 1024, "Sorry, LogLuv data must have %s=%d or %d",
  89. "Compression", COMPRESSION_SGILOG, COMPRESSION_SGILOG24);
  90. return (0);
  91. }
  92. if (td->td_planarconfig != PLANARCONFIG_CONTIG) {
  93. - sprintf(emsg, "Sorry, can not handle LogLuv images with %s=%d",
  94. + snprintf(emsg, 1024, "Sorry, can not handle LogLuv images with %s=%d",
  95. "Planarconfiguration", td->td_planarconfig);
  96. return (0);
  97. }
  98. if ( td->td_samplesperpixel != 3 || colorchannels != 3 ) {
  99. - sprintf(emsg,
  100. + snprintf(emsg, 1024,
  101. "Sorry, can not handle image with %s=%d, %s=%d",
  102. "Samples/pixel", td->td_samplesperpixel,
  103. "colorchannels", colorchannels);
  104. @@ -196,7 +196,7 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024])
  105. break;
  106. case PHOTOMETRIC_CIELAB:
  107. if ( td->td_samplesperpixel != 3 || colorchannels != 3 || td->td_bitspersample != 8 ) {
  108. - sprintf(emsg,
  109. + snprintf(emsg, 1024,
  110. "Sorry, can not handle image with %s=%d, %s=%d and %s=%d",
  111. "Samples/pixel", td->td_samplesperpixel,
  112. "colorchannels", colorchannels,
  113. @@ -205,7 +205,7 @@ TIFFRGBAImageOK(TIFF* tif, char emsg[1024])
  114. }
  115. break;
  116. default:
  117. - sprintf(emsg, "Sorry, can not handle image with %s=%d",
  118. + snprintf(emsg, 1024, "Sorry, can not handle image with %s=%d",
  119. photoTag, photometric);
  120. return (0);
  121. }
  122. @@ -303,7 +303,7 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int
  123. case 16:
  124. break;
  125. default:
  126. - sprintf(emsg, "Sorry, can not handle images with %d-bit samples",
  127. + snprintf(emsg, 1024, "Sorry, can not handle images with %d-bit samples",
  128. img->bitspersample);
  129. goto fail_return;
  130. }
  131. @@ -353,7 +353,7 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int
  132. img->photometric = PHOTOMETRIC_RGB;
  133. break;
  134. default:
  135. - sprintf(emsg, "Missing needed %s tag", photoTag);
  136. + snprintf(emsg, 1024, "Missing needed %s tag", photoTag);
  137. goto fail_return;
  138. }
  139. }
  140. @@ -361,7 +361,7 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int
  141. case PHOTOMETRIC_PALETTE:
  142. if (!TIFFGetField(tif, TIFFTAG_COLORMAP,
  143. &red_orig, &green_orig, &blue_orig)) {
  144. - sprintf(emsg, "Missing required \"Colormap\" tag");
  145. + snprintf(emsg, 1024, "Missing required \"Colormap\" tag");
  146. goto fail_return;
  147. }
  148. @@ -371,7 +371,7 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int
  149. img->greencmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color);
  150. img->bluecmap = (uint16 *) _TIFFmalloc(sizeof(uint16)*n_color);
  151. if( !img->redcmap || !img->greencmap || !img->bluecmap ) {
  152. - sprintf(emsg, "Out of memory for colormap copy");
  153. + snprintf(emsg, 1024, "Out of memory for colormap copy");
  154. goto fail_return;
  155. }
  156. @@ -385,7 +385,7 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int
  157. if (planarconfig == PLANARCONFIG_CONTIG
  158. && img->samplesperpixel != 1
  159. && img->bitspersample < 8 ) {
  160. - sprintf(emsg,
  161. + snprintf(emsg, 1024,
  162. "Sorry, can not handle contiguous data with %s=%d, "
  163. "and %s=%d and Bits/Sample=%d",
  164. photoTag, img->photometric,
  165. @@ -422,7 +422,7 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int
  166. break;
  167. case PHOTOMETRIC_RGB:
  168. if (colorchannels < 3) {
  169. - sprintf(emsg, "Sorry, can not handle RGB image with %s=%d",
  170. + snprintf(emsg, 1024, "Sorry, can not handle RGB image with %s=%d",
  171. "Color channels", colorchannels);
  172. goto fail_return;
  173. }
  174. @@ -432,12 +432,12 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int
  175. uint16 inkset;
  176. TIFFGetFieldDefaulted(tif, TIFFTAG_INKSET, &inkset);
  177. if (inkset != INKSET_CMYK) {
  178. - sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
  179. + snprintf(emsg, 1024, "Sorry, can not handle separated image with %s=%d",
  180. "InkSet", inkset);
  181. goto fail_return;
  182. }
  183. if (img->samplesperpixel < 4) {
  184. - sprintf(emsg, "Sorry, can not handle separated image with %s=%d",
  185. + snprintf(emsg, 1024, "Sorry, can not handle separated image with %s=%d",
  186. "Samples/pixel", img->samplesperpixel);
  187. goto fail_return;
  188. }
  189. @@ -445,7 +445,7 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int
  190. break;
  191. case PHOTOMETRIC_LOGL:
  192. if (compress != COMPRESSION_SGILOG) {
  193. - sprintf(emsg, "Sorry, LogL data must have %s=%d",
  194. + snprintf(emsg, 1024, "Sorry, LogL data must have %s=%d",
  195. "Compression", COMPRESSION_SGILOG);
  196. goto fail_return;
  197. }
  198. @@ -455,12 +455,12 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int
  199. break;
  200. case PHOTOMETRIC_LOGLUV:
  201. if (compress != COMPRESSION_SGILOG && compress != COMPRESSION_SGILOG24) {
  202. - sprintf(emsg, "Sorry, LogLuv data must have %s=%d or %d",
  203. + snprintf(emsg, 1024, "Sorry, LogLuv data must have %s=%d or %d",
  204. "Compression", COMPRESSION_SGILOG, COMPRESSION_SGILOG24);
  205. goto fail_return;
  206. }
  207. if (planarconfig != PLANARCONFIG_CONTIG) {
  208. - sprintf(emsg, "Sorry, can not handle LogLuv images with %s=%d",
  209. + snprintf(emsg, 1024, "Sorry, can not handle LogLuv images with %s=%d",
  210. "Planarconfiguration", planarconfig);
  211. return (0);
  212. }
  213. @@ -471,7 +471,7 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int
  214. case PHOTOMETRIC_CIELAB:
  215. break;
  216. default:
  217. - sprintf(emsg, "Sorry, can not handle image with %s=%d",
  218. + snprintf(emsg, 1024, "Sorry, can not handle image with %s=%d",
  219. photoTag, img->photometric);
  220. goto fail_return;
  221. }
  222. @@ -482,12 +482,12 @@ TIFFRGBAImageBegin(TIFFRGBAImage* img, TIFF* tif, int
  223. !(planarconfig == PLANARCONFIG_SEPARATE && img->samplesperpixel > 1);
  224. if (img->isContig) {
  225. if (!PickContigCase(img)) {
  226. - sprintf(emsg, "Sorry, can not handle image");
  227. + snprintf(emsg, 1024, "Sorry, can not handle image");
  228. goto fail_return;
  229. }
  230. } else {
  231. if (!PickSeparateCase(img)) {
  232. - sprintf(emsg, "Sorry, can not handle image");
  233. + snprintf(emsg, 1024, "Sorry, can not handle image");
  234. goto fail_return;
  235. }
  236. }