e5ac0ac
diff -rupN --no-dereference Pillow-7.2.0/src/libImaging/TiffDecode.c Pillow-7.2.0-new/src/libImaging/TiffDecode.c
e5ac0ac
--- Pillow-7.2.0/src/libImaging/TiffDecode.c	2021-03-05 21:08:18.325401446 +0100
e5ac0ac
+++ Pillow-7.2.0-new/src/libImaging/TiffDecode.c	2021-03-05 21:08:18.407401440 +0100
e5ac0ac
@@ -305,7 +305,7 @@ int _decodeStripYCbCr(Imaging im, Imagin
e5ac0ac
         img.row_offset = state->y;
e5ac0ac
         rows_to_read = min(rows_per_strip, img.height - state->y);
e5ac0ac
 
e5ac0ac
-        if (TIFFRGBAImageGet(&img, (UINT32 *)state->buffer, img.width, rows_to_read) == -1) {
e5ac0ac
+        if (!TIFFRGBAImageGet(&img, (UINT32 *)state->buffer, img.width, rows_to_read) == -1) {
e5ac0ac
             TRACE(("Decode Error, y: %d\n", state->y ));
e5ac0ac
             state->errcode = IMAGING_CODEC_BROKEN;
e5ac0ac
             TIFFRGBAImageEnd(&img;;
e5ac0ac
diff -rupN --no-dereference Pillow-7.2.0/Tests/test_tiff_crashes.py Pillow-7.2.0-new/Tests/test_tiff_crashes.py
e5ac0ac
--- Pillow-7.2.0/Tests/test_tiff_crashes.py	1970-01-01 01:00:00.000000000 +0100
e5ac0ac
+++ Pillow-7.2.0-new/Tests/test_tiff_crashes.py	2021-03-05 21:08:18.407401440 +0100
e5ac0ac
@@ -0,0 +1,40 @@
e5ac0ac
+# Reproductions/tests for crashes/read errors in TiffDecode.c
e5ac0ac
+
e5ac0ac
+# When run in Python, all of these images should fail for
e5ac0ac
+# one reason or another, either as a buffer overrun,
e5ac0ac
+# unrecognized datastream, or truncated image file.
e5ac0ac
+# There shouldn't be any segfaults.
e5ac0ac
+#
e5ac0ac
+# if run like
e5ac0ac
+# `valgrind --tool=memcheck pytest test_tiff_crashes.py 2>&1 | grep TiffDecode.c`
e5ac0ac
+# the output should be empty. There may be Python issues
e5ac0ac
+# in the valgrind especially if run in a debug Python
e5ac0ac
+# version.
e5ac0ac
+
e5ac0ac
+import pytest
e5ac0ac
+
e5ac0ac
+from PIL import Image
e5ac0ac
+
e5ac0ac
+from .helper import on_ci
e5ac0ac
+
e5ac0ac
+
e5ac0ac
+@pytest.mark.parametrize(
e5ac0ac
+    "test_file",
e5ac0ac
+    [
e5ac0ac
+        "Tests/images/crash-1152ec2d1a1a71395b6f2ce6721c38924d025bf3.tif",
e5ac0ac
+        "Tests/images/crash-0e16d3bfb83be87356d026d66919deaefca44dac.tif",
e5ac0ac
+    ],
e5ac0ac
+)
e5ac0ac
+@pytest.mark.filterwarnings("ignore:Possibly corrupt EXIF data")
e5ac0ac
+@pytest.mark.filterwarnings("ignore:Metadata warning")
e5ac0ac
+def test_tiff_crashes(test_file):
e5ac0ac
+    try:
e5ac0ac
+        with Image.open(test_file) as im:
e5ac0ac
+            im.load()
e5ac0ac
+    except FileNotFoundError:
e5ac0ac
+        if not on_ci():
e5ac0ac
+            pytest.skip("test image not found")
e5ac0ac
+            return
e5ac0ac
+        raise
e5ac0ac
+    except OSError:
e5ac0ac
+        pass