Fixed invalid argument warning#7442
Merged
hugovk merged 1 commit intopython-pillow:mainfrom Oct 13, 2023
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I noticed a warning was being raised in tests
A fuller traceback is
___________________________________________________ TestFileLibTiff.test_multipage _____________________________________________________ self = <Tests.test_file_libtiff.TestFileLibTiff object at 0x108cf1850> def test_multipage(self): # issue #862 TiffImagePlugin.READ_LIBTIFF = True with Image.open("Tests/images/multipage.tiff") as im: # file is a multipage tiff, 10x10 green, 10x10 red, 20x20 blue im.seek(0) assert im.size == (10, 10) > assert im.convert("RGB").getpixel((0, 0)) == (0, 128, 0) Tests/test_file_libtiff.py:59: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ PIL/Image.py:916: in convert self.load() PIL/TiffImagePlugin.py:1205: in load return self._load_libtiff() PIL/TiffImagePlugin.py:1303: in _load_libtiff self.load_end() PIL/TiffImagePlugin.py:1225: in load_end ImageOps.exif_transpose(self, in_place=True) PIL/ImageOps.py:592: in exif_transpose image_exif = image.getexif() PIL/Image.py:1439: in getexif self._exif.load_from_fp(self.fp, self.tag_v2._offset) PIL/Image.py:3753: in load_from_fp self._info.load(self.fp) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <PIL.TiffImagePlugin.ImageFileDirectory_v2 object at 0x108f555b0>, fp = <_io.BufferedReader name='Tests/images/multipage.tiff'> def load(self, fp): self.reset() self._offset = fp.tell() if True:#try: tag_count = ( self._unpack("Q", self._ensure_read(fp, 8)) if self._bigtiff else self._unpack("H", self._ensure_read(fp, 2)) )[0] for i in range(tag_count): tag, typ, count, data = ( self._unpack("HHQ8s", self._ensure_read(fp, 20)) if self._bigtiff else self._unpack("HHL4s", self._ensure_read(fp, 12)) ) tagname = TiffTags.lookup(tag, self.group).name typname = TYPES.get(typ, "unknown") msg = f"tag: {tagname} ({tag}) - type: {typname} ({typ})" try: unit_size, handler = self._load_dispatch[typ] except KeyError: logger.debug("%s - unsupported type %s", msg, typ) continue # ignore unsupported type size = count * unit_size if size > (8 if self._bigtiff else 4): here = fp.tell() (offset,) = self._unpack("Q" if self._bigtiff else "L", data) msg += f" Tag Location: {here} - Data Location: {offset}" fp.seek(offset) data = ImageFile._safe_read(fp, size) > fp.seek(here) E OSError: [Errno 22] Invalid argumentwhere
hereis a negative number.Taking inspiration from
Pillow/src/PIL/TiffImagePlugin.py
Lines 1131 to 1133 in 54aa8fa
I've added
self.fp.tell()intoExif.load_from_fp()to fix this.