OpenSDE Packages Database (without history before r20070)
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.

179 lines
5.4 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../libtiff/libtiff-4.0.3-0103-CVE-2013-1960.patch
  5. # Copyright (C) 2013 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. From 249e097cacd9d25d9579d7e1b46a82fd0032585d Mon Sep 17 00:00:00 2001
  17. From: tgl <tgl>
  18. Date: Thu, 2 May 2013 14:54:08 +0000
  19. Subject: [PATCH] Rewrite t2p_process_jpeg_strip(), to fix CVE-2013-1960.
  20. ----------------------------------------------------------------------------
  21. 2013-05-02 Tom Lane <tgl@sss.pgh.pa.us>
  22. * tools/tiff2pdf.c: Rewrite JPEG marker parsing in
  23. t2p_process_jpeg_strip to be at least marginally competent. The
  24. approach is still fundamentally flawed, but at least now it won't
  25. stomp all over memory when given bogus input. Fixes CVE-2013-1960.
  26. ----------------------------------------------------------------------------
  27. diff --git a/tools/tiff2pdf.c b/tools/tiff2pdf.c
  28. index b9a6075..5c424b4 100644
  29. --- a/tools/tiff2pdf.c
  30. +++ b/tools/tiff2pdf.c
  31. @@ -3341,33 +3341,56 @@ int t2p_process_jpeg_strip(
  32. uint32 height){
  33. tsize_t i=0;
  34. - uint16 ri =0;
  35. - uint16 v_samp=1;
  36. - uint16 h_samp=1;
  37. - int j=0;
  38. -
  39. - i++;
  40. -
  41. - while(i<(*striplength)){
  42. +
  43. + while (i < *striplength) {
  44. + tsize_t datalen;
  45. + uint16 ri;
  46. + uint16 v_samp;
  47. + uint16 h_samp;
  48. + int j;
  49. + int ncomp;
  50. +
  51. + /* marker header: one or more FFs */
  52. + if (strip[i] != 0xff)
  53. + return(0);
  54. + i++;
  55. + while (i < *striplength && strip[i] == 0xff)
  56. + i++;
  57. + if (i >= *striplength)
  58. + return(0);
  59. + /* SOI is the only pre-SOS marker without a length word */
  60. + if (strip[i] == 0xd8)
  61. + datalen = 0;
  62. + else {
  63. + if ((*striplength - i) <= 2)
  64. + return(0);
  65. + datalen = (strip[i+1] << 8) | strip[i+2];
  66. + if (datalen < 2 || datalen >= (*striplength - i))
  67. + return(0);
  68. + }
  69. switch( strip[i] ){
  70. - case 0xd8:
  71. - /* SOI - start of image */
  72. + case 0xd8: /* SOI - start of image */
  73. _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), 2);
  74. *bufferoffset+=2;
  75. - i+=2;
  76. break;
  77. - case 0xc0:
  78. - case 0xc1:
  79. - case 0xc3:
  80. - case 0xc9:
  81. - case 0xca:
  82. + case 0xc0: /* SOF0 */
  83. + case 0xc1: /* SOF1 */
  84. + case 0xc3: /* SOF3 */
  85. + case 0xc9: /* SOF9 */
  86. + case 0xca: /* SOF10 */
  87. if(no==0){
  88. - _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), strip[i+2]+2);
  89. - for(j=0;j<buffer[*bufferoffset+9];j++){
  90. - if( (buffer[*bufferoffset+11+(2*j)]>>4) > h_samp)
  91. - h_samp = (buffer[*bufferoffset+11+(2*j)]>>4);
  92. - if( (buffer[*bufferoffset+11+(2*j)] & 0x0f) > v_samp)
  93. - v_samp = (buffer[*bufferoffset+11+(2*j)] & 0x0f);
  94. + _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), datalen+2);
  95. + ncomp = buffer[*bufferoffset+9];
  96. + if (ncomp < 1 || ncomp > 4)
  97. + return(0);
  98. + v_samp=1;
  99. + h_samp=1;
  100. + for(j=0;j<ncomp;j++){
  101. + uint16 samp = buffer[*bufferoffset+11+(3*j)];
  102. + if( (samp>>4) > h_samp)
  103. + h_samp = (samp>>4);
  104. + if( (samp & 0x0f) > v_samp)
  105. + v_samp = (samp & 0x0f);
  106. }
  107. v_samp*=8;
  108. h_samp*=8;
  109. @@ -3381,45 +3404,43 @@ int t2p_process_jpeg_strip(
  110. (unsigned char) ((height>>8) & 0xff);
  111. buffer[*bufferoffset+6]=
  112. (unsigned char) (height & 0xff);
  113. - *bufferoffset+=strip[i+2]+2;
  114. - i+=strip[i+2]+2;
  115. -
  116. + *bufferoffset+=datalen+2;
  117. + /* insert a DRI marker */
  118. buffer[(*bufferoffset)++]=0xff;
  119. buffer[(*bufferoffset)++]=0xdd;
  120. buffer[(*bufferoffset)++]=0x00;
  121. buffer[(*bufferoffset)++]=0x04;
  122. buffer[(*bufferoffset)++]=(ri >> 8) & 0xff;
  123. buffer[(*bufferoffset)++]= ri & 0xff;
  124. - } else {
  125. - i+=strip[i+2]+2;
  126. }
  127. break;
  128. - case 0xc4:
  129. - case 0xdb:
  130. - _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), strip[i+2]+2);
  131. - *bufferoffset+=strip[i+2]+2;
  132. - i+=strip[i+2]+2;
  133. + case 0xc4: /* DHT */
  134. + case 0xdb: /* DQT */
  135. + _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), datalen+2);
  136. + *bufferoffset+=datalen+2;
  137. break;
  138. - case 0xda:
  139. + case 0xda: /* SOS */
  140. if(no==0){
  141. - _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), strip[i+2]+2);
  142. - *bufferoffset+=strip[i+2]+2;
  143. - i+=strip[i+2]+2;
  144. + _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), datalen+2);
  145. + *bufferoffset+=datalen+2;
  146. } else {
  147. buffer[(*bufferoffset)++]=0xff;
  148. buffer[(*bufferoffset)++]=
  149. (unsigned char)(0xd0 | ((no-1)%8));
  150. - i+=strip[i+2]+2;
  151. }
  152. - _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i-1]), (*striplength)-i-1);
  153. - *bufferoffset+=(*striplength)-i-1;
  154. + i += datalen + 1;
  155. + /* copy remainder of strip */
  156. + _TIFFmemcpy(&(buffer[*bufferoffset]), &(strip[i]), *striplength - i);
  157. + *bufferoffset+= *striplength - i;
  158. return(1);
  159. default:
  160. - i+=strip[i+2]+2;
  161. + /* ignore any other marker */
  162. + break;
  163. }
  164. + i += datalen + 1;
  165. }
  166. -
  167. + /* failed to find SOS marker */
  168. return(0);
  169. }
  170. #endif
  171. --
  172. 1.7.10.2