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.

101 lines
3.1 KiB

  1. From d60332057b9575ada4f264489582b13e30137be1 Mon Sep 17 00:00:00 2001
  2. From: erouault <erouault>
  3. Date: Wed, 11 Jan 2017 19:02:49 +0000
  4. Subject: [PATCH] * libtiff/tiffiop.h, tif_unix.c, tif_win32.c, tif_vms.c: add
  5. _TIFFcalloc()
  6. * libtiff/tif_read.c: TIFFReadBufferSetup(): use _TIFFcalloc() to zero
  7. initialize tif_rawdata.
  8. Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2651
  9. ---
  10. ChangeLog | 8 ++++++++
  11. libtiff/tif_read.c | 4 +++-
  12. libtiff/tif_unix.c | 8 ++++++++
  13. libtiff/tif_vms.c | 8 ++++++++
  14. libtiff/tif_win32.c | 8 ++++++++
  15. libtiff/tiffio.h | 1 +
  16. 6 files changed, 36 insertions(+), 1 deletion(-)
  17. diff --git a/ChangeLog b/ChangeLog
  18. index 6a342e5..abd75d7 100644
  19. --- a/ChangeLog
  20. +++ b/ChangeLog
  21. @@ -1,5 +1,13 @@
  22. 2017-01-11 Even Rouault <even.rouault at spatialys.com>
  23. + * libtiff/tiffiop.h, tif_unix.c, tif_win32.c, tif_vms.c: add _TIFFcalloc()
  24. +
  25. + * libtiff/tif_read.c: TIFFReadBufferSetup(): use _TIFFcalloc() to zero
  26. + initialize tif_rawdata.
  27. + Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2651
  28. +
  29. +2017-01-11 Even Rouault <even.rouault at spatialys.com>
  30. +
  31. * libtiff/tif_getimage.c: add explicit uint32 cast in putagreytile to
  32. avoid UndefinedBehaviorSanitizer warning.
  33. Patch by Nicolás Peña.
  34. diff --git a/libtiff/tif_read.c b/libtiff/tif_read.c
  35. index 277fdd6..4535ccb 100644
  36. --- a/libtiff/tif_read.c
  37. +++ b/libtiff/tif_read.c
  38. @@ -985,7 +985,9 @@ TIFFReadBufferSetup(TIFF* tif, void* bp, tmsize_t size)
  39. "Invalid buffer size");
  40. return (0);
  41. }
  42. - tif->tif_rawdata = (uint8*) _TIFFmalloc(tif->tif_rawdatasize);
  43. + /* Initialize to zero to avoid uninitialized buffers in case of */
  44. + /* short reads (http://bugzilla.maptools.org/show_bug.cgi?id=2651) */
  45. + tif->tif_rawdata = (uint8*) _TIFFcalloc(1, tif->tif_rawdatasize);
  46. tif->tif_flags |= TIFF_MYBUFFER;
  47. }
  48. if (tif->tif_rawdata == NULL) {
  49. diff --git a/libtiff/tif_unix.c b/libtiff/tif_unix.c
  50. index 7c7bc96..89dd32e 100644
  51. --- a/libtiff/tif_unix.c
  52. +++ b/libtiff/tif_unix.c
  53. @@ -316,6 +316,14 @@ _TIFFmalloc(tmsize_t s)
  54. return (malloc((size_t) s));
  55. }
  56. +void* _TIFFcalloc(tmsize_t nmemb, tmsize_t siz)
  57. +{
  58. + if( nmemb == 0 || siz == 0 )
  59. + return ((void *) NULL);
  60. +
  61. + return calloc((size_t) nmemb, (size_t)siz);
  62. +}
  63. +
  64. void
  65. _TIFFfree(void* p)
  66. {
  67. diff --git a/libtiff/tif_win32.c b/libtiff/tif_win32.c
  68. index d730b3a..3e9001b 100644
  69. --- a/libtiff/tif_win32.c
  70. +++ b/libtiff/tif_win32.c
  71. @@ -360,6 +360,14 @@ _TIFFmalloc(tmsize_t s)
  72. return (malloc((size_t) s));
  73. }
  74. +void* _TIFFcalloc(tmsize_t nmemb, tmsize_t siz)
  75. +{
  76. + if( nmemb == 0 || siz == 0 )
  77. + return ((void *) NULL);
  78. +
  79. + return calloc((size_t) nmemb, (size_t)siz);
  80. +}
  81. +
  82. void
  83. _TIFFfree(void* p)
  84. {
  85. diff --git a/libtiff/tiffio.h b/libtiff/tiffio.h
  86. index 732da17..fbd9171 100644
  87. --- a/libtiff/tiffio.h
  88. +++ b/libtiff/tiffio.h
  89. @@ -293,6 +293,7 @@ extern TIFFCodec* TIFFGetConfiguredCODECs(void);
  90. */
  91. extern void* _TIFFmalloc(tmsize_t s);
  92. +extern void* _TIFFcalloc(tmsize_t nmemb, tmsize_t siz);
  93. extern void* _TIFFrealloc(void* p, tmsize_t s);
  94. extern void _TIFFmemset(void* p, int v, tmsize_t c);
  95. extern void _TIFFmemcpy(void* d, const void* s, tmsize_t c);