Repository navigation
Raise SyntaxError for a SPIDER image within a stack opened directly - #10425
Merged
radarhere merged 3 commits intoNov 6, 2026
Merged
Conversation
An image header with stack flag 0 and image number above 0 is only read through seek(). Opening it directly raised AttributeError, so it now raises the usual SyntaxError for inconsistent stack headers.
Covers a header with stack flag 0 and image number 1: SpiderImageFile raises the inconsistent stack header SyntaxError and Image.open raises UnidentifiedImageError.
radarhere
force-pushed
the
fix/spider-image-in-stack-direct-open
branch
from
November 6, 2026 01:08
4028f87 to
1b80670
Compare
radarhere
force-pushed
the
fix/spider-image-in-stack-direct-open
branch
from
November 6, 2026 01:16
1b80670 to
60af02c
Compare
radarhere
enabled auto-merge (squash)
November 6, 2026 01:18
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.
Changes proposed in this pull request:
SpiderImageFile._open()only reads it whenseek()has already setstkoffset. When such a file is opened directly,self.stkoffsetdoes not exist andImage.open()raisesAttributeError. The other bad-header cases raiseSyntaxError, whichImage.open()turns intoUnidentifiedImageError.hasattr(self, "stkoffset")check to that branch, so a directly opened image of this kind falls through to the existing "inconsistent stack header values"SyntaxError.Tests/images/hopper.spider(image number set to 1) and expects theSyntaxErrorfromSpiderImageFileandUnidentifiedImageErrorfromImage.open().This does not change how stacks are read through
seek(). It treats a lone header of this kind as invalid. Reading it as a single image instead would be a different choice, and the SPIDER header documentation does not describe such a file as standalone.How this was found and checked:
Tests/test_file_spider.py: the new test fails on the base commit 55078c5 with theAttributeError, and the file passes (20 passed) with this change. This was run twice, in separate runs, on a source build with Python 3.12 and the codec libraries disabled.Tests/test_image.pyandTests/test_imagefile.pyshow the same 24 failures before and after this change in that build, all "decoder/encoder not available" errors from the missing codecs, and 194 passed, 9 skipped.