Skip to content

Memory map rotated TIFF images at stored size - #10222

Merged
radarhere merged 4 commits into
python-pillow:mainfrom
lazerg:fix/issue-10220-mmap-orientation
Oct 18, 2026
Merged

radarhere merged 4 commits into
python-pillow:mainfrom
lazerg:fix/issue-10220-mmap-orientation

Conversation

@lazerg

@lazerg lazerg commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

An uncompressed single-strip TIFF with Orientation 5-8 that isn't square comes out scrambled when opened by filename. Since #8390, size is the displayed (transposed) size and _tile_size holds the stored size, but the mmap branch of ImageFile.load() still mapped the buffer at self.size, so the stored rows were read at the wrong width before load_end() transposed them.

This maps the buffer, and runs the length check from #10147, at _tile_size when the image has one. Added a test for orientations 5-8.

Fixes #10220

@radarhere radarhere added the TIFF label Oct 16, 2026
@radarhere

Copy link
Copy Markdown
Member

Thanks. I've created lazerg#7 with a suggestion.

@lazerg

lazerg commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, merged. I switched the test back to hopper("L") in 85dc302, since RGB isn't memory mapped and the test passed even without the fix. Also, if load() raises, _size stays at the stored size, so a try/finally might be worth adding.

@radarhere

Copy link
Copy Markdown
Member

Ah, yes, thanks. I've pushed a commit to add a try block.

@radarhere
radarhere merged commit 3f6d442 into python-pillow:main Oct 18, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rotated TIFF gets scrambled when opened by filename

2 participants