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.

44 lines
1.6 KiB

  1. From 5c3bc1c78dfe05eb5f4224650ad606b75e1f7034 Mon Sep 17 00:00:00 2001
  2. From: Even Rouault <even.rouault@spatialys.com>
  3. Date: Sun, 11 Mar 2018 11:14:01 +0100
  4. Subject: [PATCH] ChopUpSingleUncompressedStrip: avoid memory exhaustion
  5. (CVE-2017-11613)
  6. In ChopUpSingleUncompressedStrip(), if the computed number of strips is big
  7. enough and we are in read only mode, validate that the file size is consistent
  8. with that number of strips to avoid useless attempts at allocating a lot of
  9. memory for the td_stripbytecount and td_stripoffset arrays.
  10. Rework fix done in 3719385a3fac5cfb20b487619a5f08abbf967cf8 to work in more
  11. cases like https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=6979.
  12. Credit to OSS Fuzz
  13. Fixes http://bugzilla.maptools.org/show_bug.cgi?id=2724
  14. ---
  15. libtiff/tif_dirread.c | 10 ++++++++++
  16. 1 file changed, 10 insertions(+)
  17. diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c
  18. index 80aaf8d..5896a78 100644
  19. --- a/libtiff/tif_dirread.c
  20. +++ b/libtiff/tif_dirread.c
  21. @@ -5760,6 +5760,16 @@ ChopUpSingleUncompressedStrip(TIFF* tif)
  22. if( nstrips == 0 )
  23. return;
  24. + /* If we are going to allocate a lot of memory, make sure that the */
  25. + /* file is as big as needed */
  26. + if( tif->tif_mode == O_RDONLY &&
  27. + nstrips > 1000000 &&
  28. + (offset >= TIFFGetFileSize(tif) ||
  29. + stripbytes > (TIFFGetFileSize(tif) - offset) / (nstrips - 1)) )
  30. + {
  31. + return;
  32. + }
  33. +
  34. newcounts = (uint64*) _TIFFCheckMalloc(tif, nstrips, sizeof (uint64),
  35. "for chopped \"StripByteCounts\" array");
  36. newoffsets = (uint64*) _TIFFCheckMalloc(tif, nstrips, sizeof (uint64),
  37. --
  38. 2.17.1