From 2ca9db3ebacc6fb3cb3ce1fcacb38d8ff8f05e06 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Fri, 12 Jun 2020 09:57:21 -0400 Subject: [PATCH] Guard against reading tiff tiles outside of the image. --- sources/tiff/large_image_source_tiff/__init__.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sources/tiff/large_image_source_tiff/__init__.py b/sources/tiff/large_image_source_tiff/__init__.py index c47ef6cb1..b1fa379b0 100644 --- a/sources/tiff/large_image_source_tiff/__init__.py +++ b/sources/tiff/large_image_source_tiff/__init__.py @@ -277,6 +277,13 @@ def getTile(self, x, y, z, pilImageAllowed=False, numpyAllowed=False, sparseFallback=False, **kwargs): if z < 0: raise TileSourceException('z layer does not exist') + scale = 2 ** (self.levels - 1 - z) + offsetx = x * self.tileWidth * scale + if not (0 <= offsetx < self.sizeX): + raise TileSourceException('x is outside layer') + offsety = y * self.tileHeight * scale + if not (0 <= offsety < self.sizeY): + raise TileSourceException('y is outside layer') try: allowStyle = True if self._tiffDirectories[z] is None: