From 2995fb67c1770af679216380e1ea12c0c33aeee2 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 13 Jul 2019 13:50:13 +1000 Subject: [PATCH] Return after error --- Tests/test_file_jpeg2k.py | 6 ++++++ src/encode.c | 2 ++ 2 files changed, 8 insertions(+) diff --git a/Tests/test_file_jpeg2k.py b/Tests/test_file_jpeg2k.py index a2483fade..3ca99486c 100644 --- a/Tests/test_file_jpeg2k.py +++ b/Tests/test_file_jpeg2k.py @@ -90,6 +90,12 @@ class TestFileJpeg2k(PillowTestCase): ) self.assert_image_equal(im, test_card) + def test_tiled_offset_too_small(self): + with self.assertRaises(ValueError): + self.roundtrip( + test_card, tile_size=(128, 128), tile_offset=(0, 0), offset=(128, 32) + ) + def test_irreversible_rt(self): im = self.roundtrip(test_card, irreversible=True, quality_layers=[20]) self.assert_image_similar(im, test_card, 2.0) diff --git a/src/encode.c b/src/encode.c index ac729f455..7dc1035c4 100644 --- a/src/encode.c +++ b/src/encode.c @@ -1211,6 +1211,8 @@ PyImaging_Jpeg2KEncoderNew(PyObject *self, PyObject *args) PyErr_SetString(PyExc_ValueError, "JPEG 2000 tile offset too small; top left tile must " "intersect image area"); + Py_DECREF(encoder); + return NULL; } if (context->tile_offset_x > context->offset_x