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.

129 lines
4.0 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-0100-CVE-2012-4564.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 fd1356f7003d47cf59392679c08a2dacc556bce4 Mon Sep 17 00:00:00 2001
  17. From: fwarmerdam <fwarmerdam>
  18. Date: Fri, 2 Nov 2012 05:13:24 +0000
  19. Subject: [PATCH] ppm2tiff: fix zero size buffer exploit (CVE-2012-4564)
  20. original commit message: fix zero size buffer exploit (CVE-2012-4564) in ppm2tiff
  21. original ChangeLog entry:
  22. ----------------------------------------------------------------------------
  23. 2012-11-01 Frank Warmerdam <warmerdam@pobox.com>
  24. * tools/ppm2tiff.c: avoid zero size buffer vulnerability.
  25. CVE-2012-4564 - Thanks to Huzaifa Sidhpurwala of the
  26. Red Hat Security Response team for the fix.
  27. ----------------------------------------------------------------------------
  28. original commit message: Improve previous patch for CVE-2012-4564.
  29. original ChangeLog entry:
  30. ----------------------------------------------------------------------------
  31. 2012-12-10 Tom Lane <tgl@sss.pgh.pa.us>
  32. * tools/ppm2tiff.c: Improve previous patch for CVE-2012-4564:
  33. check the linebytes calculation too, get the max() calculation
  34. straight, avoid redundant error messages, check for malloc
  35. failure.
  36. ----------------------------------------------------------------------------
  37. diff --git a/tools/ppm2tiff.c b/tools/ppm2tiff.c
  38. index 8910e76..d2f72a2 100644
  39. --- a/tools/ppm2tiff.c
  40. +++ b/tools/ppm2tiff.c
  41. @@ -72,6 +72,17 @@ BadPPM(char* file)
  42. exit(-2);
  43. }
  44. +static tmsize_t
  45. +multiply_ms(tmsize_t m1, tmsize_t m2)
  46. +{
  47. + tmsize_t bytes = m1 * m2;
  48. +
  49. + if (m1 && bytes / m1 != m2)
  50. + bytes = 0;
  51. +
  52. + return bytes;
  53. +}
  54. +
  55. int
  56. main(int argc, char* argv[])
  57. {
  58. @@ -79,7 +90,7 @@ main(int argc, char* argv[])
  59. uint32 rowsperstrip = (uint32) -1;
  60. double resolution = -1;
  61. unsigned char *buf = NULL;
  62. - tsize_t linebytes = 0;
  63. + tmsize_t linebytes = 0;
  64. uint16 spp = 1;
  65. uint16 bpp = 8;
  66. TIFF *out;
  67. @@ -89,6 +100,7 @@ main(int argc, char* argv[])
  68. int c;
  69. extern int optind;
  70. extern char* optarg;
  71. + tmsize_t scanline_size;
  72. if (argc < 2) {
  73. fprintf(stderr, "%s: Too few arguments\n", argv[0]);
  74. @@ -221,7 +233,8 @@ main(int argc, char* argv[])
  75. }
  76. switch (bpp) {
  77. case 1:
  78. - linebytes = (spp * w + (8 - 1)) / 8;
  79. + /* if round-up overflows, result will be zero, OK */
  80. + linebytes = (multiply_ms(spp, w) + (8 - 1)) / 8;
  81. if (rowsperstrip == (uint32) -1) {
  82. TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, h);
  83. } else {
  84. @@ -230,15 +243,31 @@ main(int argc, char* argv[])
  85. }
  86. break;
  87. case 8:
  88. - linebytes = spp * w;
  89. + linebytes = multiply_ms(spp, w);
  90. TIFFSetField(out, TIFFTAG_ROWSPERSTRIP,
  91. TIFFDefaultStripSize(out, rowsperstrip));
  92. break;
  93. }
  94. - if (TIFFScanlineSize(out) > linebytes)
  95. + if (linebytes == 0) {
  96. + fprintf(stderr, "%s: scanline size overflow\n", infile);
  97. + (void) TIFFClose(out);
  98. + exit(-2);
  99. + }
  100. + scanline_size = TIFFScanlineSize(out);
  101. + if (scanline_size == 0) {
  102. + /* overflow - TIFFScanlineSize already printed a message */
  103. + (void) TIFFClose(out);
  104. + exit(-2);
  105. + }
  106. + if (scanline_size < linebytes)
  107. buf = (unsigned char *)_TIFFmalloc(linebytes);
  108. else
  109. - buf = (unsigned char *)_TIFFmalloc(TIFFScanlineSize(out));
  110. + buf = (unsigned char *)_TIFFmalloc(scanline_size);
  111. + if (buf == NULL) {
  112. + fprintf(stderr, "%s: Not enough memory\n", infile);
  113. + (void) TIFFClose(out);
  114. + exit(-2);
  115. + }
  116. if (resolution > 0) {
  117. TIFFSetField(out, TIFFTAG_XRESOLUTION, resolution);
  118. TIFFSetField(out, TIFFTAG_YRESOLUTION, resolution);
  119. --
  120. 1.7.10.2