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.

53 lines
1.4 KiB

  1. From 1c127eb3cb7653bd61b61f9c3cfeb36fd10edab1 Mon Sep 17 00:00:00 2001
  2. From: Even Rouault <even.rouault@spatialys.com>
  3. Date: Sat, 12 May 2018 15:32:31 +0200
  4. Subject: [PATCH 3/4] LZWDecodeCompat(): fix potential index-out-of-bounds
  5. write. Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2780 /
  6. CVE-2018-8905
  7. The fix consists in using the similar code LZWDecode() to validate we
  8. don't write outside of the output buffer.
  9. ---
  10. libtiff/tif_lzw.c | 18 ++++++++++++------
  11. 1 file changed, 12 insertions(+), 6 deletions(-)
  12. diff --git a/libtiff/tif_lzw.c b/libtiff/tif_lzw.c
  13. index bc8f9c8..186ea3c 100644
  14. --- a/libtiff/tif_lzw.c
  15. +++ b/libtiff/tif_lzw.c
  16. @@ -604,6 +604,7 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
  17. char *tp;
  18. unsigned char *bp;
  19. int code, nbits;
  20. + int len;
  21. long nextbits, nextdata, nbitsmask;
  22. code_t *codep, *free_entp, *maxcodep, *oldcodep;
  23. @@ -755,13 +756,18 @@ LZWDecodeCompat(TIFF* tif, uint8* op0, tmsize_t occ0, uint16 s)
  24. } while (--occ);
  25. break;
  26. }
  27. - assert(occ >= codep->length);
  28. - op += codep->length;
  29. - occ -= codep->length;
  30. - tp = op;
  31. + len = codep->length;
  32. + tp = op + len;
  33. do {
  34. - *--tp = codep->value;
  35. - } while( (codep = codep->next) != NULL );
  36. + int t;
  37. + --tp;
  38. + t = codep->value;
  39. + codep = codep->next;
  40. + *tp = (char)t;
  41. + } while (codep && tp > op);
  42. + assert(occ >= len);
  43. + op += len;
  44. + occ -= len;
  45. } else {
  46. *op++ = (char)code;
  47. occ--;
  48. --
  49. 2.17.0