From dc7470f2afd6232a3400c421b72431711cbd7f63 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Sun, 18 Aug 2024 20:38:41 -0500 Subject: [PATCH] add more data to error message --- src/PIL/TiffImagePlugin.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index deae199d50e..9dbbe1bfa5e 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -2133,17 +2133,27 @@ def fixIFD(self) -> None: if tag in self.Tags: cur_pos = self.f.tell() - if is_local: - self.fixOffsets( - count, isShort=(field_size == 2), isLong=(field_size == 4) - ) - self.f.seek(cur_pos + 4) - else: - self.f.seek(offset) - self.fixOffsets( - count, isShort=(field_size == 2), isLong=(field_size == 4) + try: + if is_local: + self.fixOffsets( + count, isShort=(field_size == 2), isLong=(field_size == 4) + ) + self.f.seek(cur_pos + 4) + else: + self.f.seek(offset) + self.fixOffsets( + count, isShort=(field_size == 2), isLong=(field_size == 4) + ) + self.f.seek(cur_pos) + except RuntimeError as e: + msg = ( + f"{e}:" + f" Tag ID {tag}" + f" Field Type {field_type}" + f" Field Size {field_size}" + f" Count {count}" ) - self.f.seek(cur_pos) + raise RuntimeError(msg) from e elif is_local: # skip the locally stored value that is not an offset