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.

72 lines
2.5 KiB

  1. From 237c9c18b0b3479950e54a755ae428bf0f55f754 Mon Sep 17 00:00:00 2001
  2. From: erouault <erouault>
  3. Date: Sun, 27 Dec 2015 16:55:20 +0000
  4. Subject: [PATCH] * libtiff/tif_next.c: fix potential out-of-bound write in
  5. NeXTDecode() triggered by http://lcamtuf.coredump.cx/afl/vulns/libtiff5.tif
  6. (bugzilla #2508)
  7. ---
  8. ChangeLog | 6 ++++++
  9. libtiff/tif_next.c | 12 +++++++++---
  10. 2 files changed, 15 insertions(+), 3 deletions(-)
  11. diff --git a/ChangeLog b/ChangeLog
  12. index b8aa23c..04926a3 100644
  13. --- a/ChangeLog
  14. +++ b/ChangeLog
  15. @@ -1,5 +1,11 @@
  16. 2015-12-27 Even Rouault <even.rouault at spatialys.com>
  17. + * libtiff/tif_next.c: fix potential out-of-bound write in NeXTDecode()
  18. + triggered by http://lcamtuf.coredump.cx/afl/vulns/libtiff5.tif
  19. + (bugzilla #2508)
  20. +
  21. +2015-12-27 Even Rouault <even.rouault at spatialys.com>
  22. +
  23. * libtiff/tif_luv.c: fix potential out-of-bound writes in decode
  24. functions in non debug builds by replacing assert()s by regular if
  25. checks (bugzilla #2522).
  26. diff --git a/libtiff/tif_next.c b/libtiff/tif_next.c
  27. index 17e0311..1248caa 100644
  28. --- a/libtiff/tif_next.c
  29. +++ b/libtiff/tif_next.c
  30. @@ -1,4 +1,4 @@
  31. -/* $Id: tif_next.c,v 1.16 2014-12-29 12:09:11 erouault Exp $ */
  32. +/* $Id: tif_next.c,v 1.17 2015-12-27 16:55:20 erouault Exp $ */
  33. /*
  34. * Copyright (c) 1988-1997 Sam Leffler
  35. @@ -37,7 +37,7 @@
  36. case 0: op[0] = (unsigned char) ((v) << 6); break; \
  37. case 1: op[0] |= (v) << 4; break; \
  38. case 2: op[0] |= (v) << 2; break; \
  39. - case 3: *op++ |= (v); break; \
  40. + case 3: *op++ |= (v); op_offset++; break; \
  41. } \
  42. }
  43. @@ -106,6 +106,7 @@ NeXTDecode(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s)
  44. uint32 imagewidth = tif->tif_dir.td_imagewidth;
  45. if( isTiled(tif) )
  46. imagewidth = tif->tif_dir.td_tilewidth;
  47. + tmsize_t op_offset = 0;
  48. /*
  49. * The scanline is composed of a sequence of constant
  50. @@ -122,10 +123,15 @@ NeXTDecode(TIFF* tif, uint8* buf, tmsize_t occ, uint16 s)
  51. * bounds, potentially resulting in a security
  52. * issue.
  53. */
  54. - while (n-- > 0 && npixels < imagewidth)
  55. + while (n-- > 0 && npixels < imagewidth && op_offset < scanline)
  56. SETPIXEL(op, grey);
  57. if (npixels >= imagewidth)
  58. break;
  59. + if (op_offset >= scanline ) {
  60. + TIFFErrorExt(tif->tif_clientdata, module, "Invalid data for scanline %ld",
  61. + (long) tif->tif_row);
  62. + return (0);
  63. + }
  64. if (cc == 0)
  65. goto bad;
  66. n = *bp++, cc--;