diff --git a/libtiff/tif_dirread.c b/libtiff/tif_dirread.c
index 6f90941..1c8e97d 100644
--- a/libtiff/tif_dirread.c
+++ b/libtiff/tif_dirread.c
@@ -5875,6 +5875,16 @@ ChopUpSingleUncompressedStrip(TIFF* tif)
         if( nstrips == 0 )
             return;
 
+        /* If we are going to allocate a lot of memory, make sure that the */
+        /* file is as big as needed */
+        if( tif->tif_mode == O_RDONLY &&
+            nstrips > 1000000 &&
+	    (offset >= TIFFGetFileSize(tif) ||
+             stripbytes > (TIFFGetFileSize(tif) - offset) / (nstrips - 1)) )
+        {
+            return;
+        }
+
         /* If we are going to allocate a lot of memory, make sure that the */
         /* file is as big as needed */
         if( tif->tif_mode == O_RDONLY &&
