openslide-python icon indicating copy to clipboard operation
openslide-python copied to clipboard

PIL.UnidentifiedImageError: cannot identify image file

Open syy-create opened this issue 2 years ago • 6 comments

Operating system

Ubuntu

Platform

64-bit x86

OpenSlide Python version

1.3.1

OpenSlide version

3.4.1

Slide format

svs

Issue details

when I read other SVS files, I can read them normally, within 2GB of SVS files. Today, there was a read error while reading an SVS file with a file size of 4GB. Does Openslide not support reading such a large SVS file? I'm getting this error when trying to read the test.svs file. I tested openslide-python installed through both pip and conda. import openslide slide = openslide.open_slide(r'test.svs') Traceback (most recent call last): File "/home/testa.py", line 3, in File "/home/anaconda3/envs/torch11.6/lib/python3.8/site-packages/openslide/init.py", line 353, in init self._image = Image.open(file) File "/home/anaconda3/envs/torch11.6/lib/python3.8/site-packages/PIL/Image.py", line 3280, in open raise UnidentifiedImageError(msg) PIL.UnidentifiedImageError: cannot identify image file 'test.svs'.

syy-create avatar Nov 30 '23 12:11 syy-create

It may be a file issue, I will temporarily close the issue.

syy-create avatar Nov 30 '23 12:11 syy-create

openslide.open_slide() falls back to PIL.Image if OpenSlide can't read the file, obscuring the original error message. If you open the file with openslide.OpenSlide() instead, you'll get an exception with OpenSlide's original error.

It's possible that OpenSlide has trouble with large SVS files. If you can submit a sample slide that shows the problem, I can take a look at it.

bgilbert avatar Nov 30 '23 18:11 bgilbert

openslide.open_slide() falls back to PIL.Image if OpenSlide can't read the file, obscuring the original error message. If you open the file with openslide.OpenSlide() instead, you'll get an exception with OpenSlide's original error.

It's possible that OpenSlide has trouble with large SVS files. If you can submit a sample slide that shows the problem, I can take a look at it.

I'm very sorry for replying to you only now. After inquiry, I found out that this is a private dataset of the hospital, and they do not agree to share it externally. So I cannot upload. I checked those SVS files again and found that some of them were incorrect, so I deleted those images. In addition, I found that for SVS that occupies a large amount of memory (currently 4GB for me), When the ### open_ slide() method is used for reading, the following error will be displayed: Image size (14393580812 pixels) exceeds limit of 178956970 pixels, could be decompression Bomb DOS attack, May I ask if you have a good solution.

syy-create avatar Dec 02 '23 08:12 syy-create

Please try opening the slide with openslide.OpenSlide() and report the error you receive.

bgilbert avatar Dec 02 '23 08:12 bgilbert

Please try opening the slide with openslide.OpenSlide() and report the error you receive.

The following is using Openslide Error message for OpenSlide(): Traceback (most recent call last): File "/home/testa.py", line 5, in slide = openslide.OpenSlide(r'/home/testa/test.svs') File "/home/anaconda3/envs/torch11.6/lib/python3.8/site-packages/openslide/init.py", line 179, in init self._osr = lowlevel.open(str(filename)) File "/home/anaconda3/envs/torch11.6/lib/python3.8/site-packages/openslide/lowlevel.py", line 203, in _check_open raise OpenSlideUnsupportedFormatError("Unsupported or missing image file") openslide.lowlevel.OpenSlideUnsupportedFormatError: Unsupported or missing image file

The following is using open_ Error message for slide(): Traceback (most recent call last): File "/home/anaconda3/envs/torch11.6/lib/python3.8/site-packages/openslide/init.py", line 463, in open_slide return OpenSlide(filename) File "/home/anaconda3/envs/torch11.6/lib/python3.8/site-packages/openslide/init.py", line 179, in init self._osr = lowlevel.open(str(filename)) File "/home/anaconda3/envs/torch11.6/lib/python3.8/site-packages/openslide/lowlevel.py", line 203, in _check_open raise OpenSlideUnsupportedFormatError("Unsupported or missing image file") openslide.lowlevel.OpenSlideUnsupportedFormatError: Unsupported or missing image file

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/home/testa.py", line 5, in slide = openslide.open_slide(r'/home/testa/test.svs') File "/home/anaconda3/envs/torch11.6/lib/python3.8/site-packages/openslide/init.py", line 465, in open_slide return ImageSlide(filename) File "/home/anaconda3/envs/torch11.6/lib/python3.8/site-packages/openslide/init.py", line 353, in init self._image = Image.open(file) File "/home/anaconda3/envs/torch11.6/lib/python3.8/site-packages/PIL/Image.py", line 3264, in open im = _open_core( File "/home/anaconda3/envs/torch11.6/lib/python3.8/site-packages/PIL/Image.py", line 3246, in _open_core _decompression_bomb_check(im.size) File "/home/anaconda3/envs/torch11.6/lib/python3.8/site-packages/PIL/Image.py", line 3154, in _decompression_bomb_check raise DecompressionBombError(msg) PIL.Image.DecompressionBombError: Image size (13928508818 pixels) exceeds limit of 178956970 pixels, could be decompression bomb DOS attack. Process finished with exit code 1

syy-create avatar Dec 02 '23 09:12 syy-create

Hmm, okay. Could you try setting the OPENSLIDE_DEBUG environment variable to detection? That'll report the reason that each OpenSlide driver is rejecting the file. You can do this when starting Python with:

OPENSLIDE_DEBUG=detection python3

bgilbert avatar Dec 03 '23 05:12 bgilbert

From the error message, it appears that OpenSlide doesn't think it supports these slide files. Without additional information, I can't debug this further, so I'll close. If you're able to provide additional information, please feel free to post it here or file a new bug in the OpenSlide issue tracker.

bgilbert avatar Sep 07 '24 04:09 bgilbert