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.

60 lines
2.5 KiB

  1. From 3cfd62d77c2a7e147a05bd678524c345fa9c2bb8 Mon Sep 17 00:00:00 2001
  2. From: erouault <erouault>
  3. Date: Wed, 11 Jan 2017 13:28:01 +0000
  4. Subject: [PATCH] * libtiff/tif_dirread.c: avoid division by floating point 0
  5. in TIFFReadDirEntryCheckedRational() and TIFFReadDirEntryCheckedSrational(),
  6. and return 0 in that case (instead of infinity as before presumably)
  7. Apparently some sanitizers do not like those divisions by zero. Fixes
  8. http://bugzilla.maptools.org/show_bug.cgi?id=2644
  9. ---
  10. ChangeLog | 8 ++++++++
  11. libtiff/tif_dirread.c | 10 ++++++++--
  12. 2 files changed, 16 insertions(+), 2 deletions(-)
  13. diff --git a/ChangeLog b/ChangeLog
  14. index 6a752cd..722a405 100644
  15. --- a/ChangeLog
  16. +++ b/ChangeLog
  17. @@ -1,5 +1,13 @@
  18. 2017-01-11 Even Rouault <even.rouault at spatialys.com>
  19. + * libtiff/tif_dirread.c: avoid division by floating point 0 in
  20. + TIFFReadDirEntryCheckedRational() and TIFFReadDirEntryCheckedSrational(),
  21. + and return 0 in that case (instead of infinity as before presumably)
  22. + Apparently some sanitizers do not like those divisions by zero.
  23. + Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2644
  24. +
  25. +2017-01-11 Even Rouault <even.rouault at spatialys.com>
  26. +
  27. * libtiff/tif_jpeg.c: avoid integer division by zero in
  28. JPEGSetupEncode() when horizontal or vertical sampling is set to 0.
  29. Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2653
  30. diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c
  31. index 570d0c3..8a1e42a 100644
  32. --- a/libtiff/tif_dirread.c
  33. +++ b/libtiff/tif_dirread.c
  34. @@ -2872,7 +2872,10 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedRational(TIFF* tif, TIFFD
  35. m.l = direntry->tdir_offset.toff_long8;
  36. if (tif->tif_flags&TIFF_SWAB)
  37. TIFFSwabArrayOfLong(m.i,2);
  38. - if (m.i[0]==0)
  39. + /* Not completely sure what we should do when m.i[1]==0, but some */
  40. + /* sanitizers do not like division by 0.0: */
  41. + /* http://bugzilla.maptools.org/show_bug.cgi?id=2644 */
  42. + if (m.i[0]==0 || m.i[1]==0)
  43. *value=0.0;
  44. else
  45. *value=(double)m.i[0]/(double)m.i[1];
  46. @@ -2900,7 +2903,10 @@ static enum TIFFReadDirEntryErr TIFFReadDirEntryCheckedSrational(TIFF* tif, TIFF
  47. m.l=direntry->tdir_offset.toff_long8;
  48. if (tif->tif_flags&TIFF_SWAB)
  49. TIFFSwabArrayOfLong(m.i,2);
  50. - if ((int32)m.i[0]==0)
  51. + /* Not completely sure what we should do when m.i[1]==0, but some */
  52. + /* sanitizers do not like division by 0.0: */
  53. + /* http://bugzilla.maptools.org/show_bug.cgi?id=2644 */
  54. + if ((int32)m.i[0]==0 || m.i[1]==0)
  55. *value=0.0;
  56. else
  57. *value=(double)((int32)m.i[0])/(double)m.i[1];