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.

67 lines
2.3 KiB

  1. From 66e7bd59520996740e4df5495a830b42fae48bc4 Mon Sep 17 00:00:00 2001
  2. From: erouault <erouault>
  3. Date: Wed, 11 Jan 2017 16:33:34 +0000
  4. Subject: [PATCH] * libtiff/tif_read.c: avoid potential undefined behaviour on
  5. signed integer addition in TIFFReadRawStrip1() in isMapped() case. Fixes
  6. http://bugzilla.maptools.org/show_bug.cgi?id=2650
  7. ---
  8. ChangeLog | 6 ++++++
  9. libtiff/tif_read.c | 27 ++++++++++++++++++---------
  10. 2 files changed, 24 insertions(+), 9 deletions(-)
  11. diff --git a/ChangeLog b/ChangeLog
  12. index 8e202a2..3e31464 100644
  13. --- a/ChangeLog
  14. +++ b/ChangeLog
  15. @@ -1,5 +1,11 @@
  16. 2017-01-11 Even Rouault <even.rouault at spatialys.com>
  17. + * libtiff/tif_read.c: avoid potential undefined behaviour on signed integer
  18. + addition in TIFFReadRawStrip1() in isMapped() case.
  19. + Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2650
  20. +
  21. +2017-01-11 Even Rouault <even.rouault at spatialys.com>
  22. +
  23. * libtiff/tif_jpeg.c: validate BitsPerSample in JPEGSetupEncode() to avoid
  24. undefined behaviour caused by invalid shift exponent.
  25. Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2648
  26. diff --git a/libtiff/tif_read.c b/libtiff/tif_read.c
  27. index 52bbf50..b7aacbd 100644
  28. --- a/libtiff/tif_read.c
  29. +++ b/libtiff/tif_read.c
  30. @@ -420,16 +420,25 @@ TIFFReadRawStrip1(TIFF* tif, uint32 strip, void* buf, tmsize_t size,
  31. return ((tmsize_t)(-1));
  32. }
  33. } else {
  34. - tmsize_t ma,mb;
  35. + tmsize_t ma;
  36. tmsize_t n;
  37. - ma=(tmsize_t)td->td_stripoffset[strip];
  38. - mb=ma+size;
  39. - if ((td->td_stripoffset[strip] > (uint64)TIFF_TMSIZE_T_MAX)||(ma>tif->tif_size))
  40. - n=0;
  41. - else if ((mb<ma)||(mb<size)||(mb>tif->tif_size))
  42. - n=tif->tif_size-ma;
  43. - else
  44. - n=size;
  45. + if ((td->td_stripoffset[strip] > (uint64)TIFF_TMSIZE_T_MAX)||
  46. + ((ma=(tmsize_t)td->td_stripoffset[strip])>tif->tif_size))
  47. + {
  48. + n=0;
  49. + }
  50. + else if( ma > TIFF_TMSIZE_T_MAX - size )
  51. + {
  52. + n=0;
  53. + }
  54. + else
  55. + {
  56. + tmsize_t mb=ma+size;
  57. + if (mb>tif->tif_size)
  58. + n=tif->tif_size-ma;
  59. + else
  60. + n=size;
  61. + }
  62. if (n!=size) {
  63. #if defined(__WIN32__) && (defined(_MSC_VER) || defined(__MINGW32__))
  64. TIFFErrorExt(tif->tif_clientdata, module,