Skip to content

Conversation

@metalerk
Copy link
Contributor

Fixes #1976

Fix thumbnail generation crash when Pillow drops image.format after resizing.
Preserve original image_format in upload pipeline and fall back safely to PNG when missing.

@rafalp
Copy link
Owner

rafalp commented Aug 17, 2025

I appreciate you contributing to Misago, but can you please finish addressing one PR review before opening the next one? I've left you bunch of comments in #1980 that still need addressing. Thanks!

"WEBP": "image/webp",
"TIFF": "image/tiff",
"BMP": "image/bmp",
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong way to go about this. Pillow already knows what format image is, via image.format attribute. It just loses this attribute when it downscales initial image if it's too big. We should find a way to keep this initial image.format attribute instead of introducing extra logic.

@rafalp
Copy link
Owner

rafalp commented Aug 20, 2025

The good way to go about this is:

Add image_format: str option to generate_attachment_thumbnail.

Update generate_attachment_thumbnail calls to pass image_format from outside.

@metalerk
Copy link
Contributor Author

The good way to go about this is:

Add image_format: str option to generate_attachment_thumbnail.

Update generate_attachment_thumbnail calls to pass image_format from outside.

Thanks for the hint! I'll update accordingly

@metalerk metalerk force-pushed the attachment-image-size-breaks-thumbnails branch from 45c5b5e to 136fe33 Compare August 21, 2025 15:35
Copy link
Owner

@rafalp rafalp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs two tests:

  • Uploaded attachment with width greater than max_width
  • Ditto, but height greater than max_height

@coveralls
Copy link

coveralls commented Aug 21, 2025

Coverage Status

coverage: 96.943% (+0.005%) from 96.938%
when pulling 8792d1a on metalerk:attachment-image-size-breaks-thumbnails
into 1524809 on rafalp:main.

pytest.param(400, 1000, id="max_width_greater"),
],
)
def test_generate_attachment_thumbnail_generates_thumbnail_image_and_updates_attachment_gt_max_dimensions(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function that you should test is store_uploaded_file, not generate_attachment_thumbnail

@metalerk
Copy link
Contributor Author

Hi @rafalp
I've been quite busy these days but I'll try to finish it this week. My apologies for the delay.

@rafalp
Copy link
Owner

rafalp commented Nov 3, 2025

Merged as part of #2013, thank you <3

@rafalp rafalp closed this Nov 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Max attachment image size breaks thumbnails

3 participants