Skip to content

fix(preview): handle null mime type in preview generation#58802

Open
boris324 wants to merge 1 commit intonextcloud:masterfrom
boris324:fix/preview-null-mimetype
Open

fix(preview): handle null mime type in preview generation#58802
boris324 wants to merge 1 commit intonextcloud:masterfrom
boris324:fix/preview-null-mimetype

Conversation

@boris324
Copy link

@boris324 boris324 commented Mar 9, 2026

Fixes #58784

IImage::dataMimeType() can return null for edge-case images (e.g. a GIF with dimensions 18x4312), but Preview::setMimeType() expects a non-null string. This causes a TypeError during preview generation.

This patch adds a null coalesce fallback to image/png (the default preview format) at both call sites in Generator.php where dataMimeType() is passed to setMimeType(). This prevents the crash and allows preview generation to complete gracefully.

Added a test case covering preview generation when the image has a null MIME type.

@boris324 boris324 requested a review from a team as a code owner March 9, 2026 11:43
@boris324 boris324 requested review from ArtificialOwl, artonge, nfebe and sorbaugh and removed request for a team March 9, 2026 11:43
@solracsf
Copy link
Member

solracsf commented Mar 9, 2026

Another approach here: #58793

Cc @CarlSchwan since you reviewed ;)

PS: why set a default mimetype to png if it fails? Seems arbitrary, but maybe I just don't get it 🤔

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.

[Bug]: preview generation crashes on image files when generated preview has null MIME type

2 participants