Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optionally generate thumbnails for invalid images #11126

Merged
merged 7 commits into from
Jul 18, 2024

Conversation

Saschl
Copy link
Contributor

@Saschl Saschl commented Jul 15, 2024

First PR here, there are some questions. Came from a suggestion on discord.

@@ -45,7 +46,8 @@ export class MediaRepository implements IMediaRepository {
}

async generateThumbnail(input: string | Buffer, output: string, options: ThumbnailOptions): Promise<void> {
const pipeline = sharp(input, { failOn: 'error', limitInputPixels: false })
// some invalid images can still be processed by sharp, but we want to fail on them by default to avoid crashes
const pipeline = sharp(input, { failOn: PROCESS_INVALID_IMAGES ? 'none' : 'error', limitInputPixels: false })
Copy link
Contributor Author

@Saschl Saschl Jul 15, 2024

Choose a reason for hiding this comment

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

Not really sure if using an import from constants is the right choice here. Might also include it in the options object, which would make it better testable. But I guess that's something that shouldn't be configurable in the UI?

Copy link
Contributor

@mertalev mertalev Jul 15, 2024

Choose a reason for hiding this comment

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

For testing, I think it should be a field in options. We don't need to expose it in the UI since this is a more niche scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done that and added a test case. Not too sure about accessing the env directly in the service, let me know if you have other suggestions :)

@@ -27,6 +27,8 @@ export const WEB_ROOT = process.env.IMMICH_WEB_ROOT || '/usr/src/app/www';
const HOST_SERVER_PORT = process.env.IMMICH_PORT || '2283';
export const DEFAULT_EXTERNAL_DOMAIN = 'http://localhost:' + HOST_SERVER_PORT;

export const PROCESS_INVALID_IMAGES = process.env.IMMICH_PROCESS_INVALID_IMAGES === 'true';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would this need to be documented as well (independent from where the option will be in the end)?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it should be added here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@alextran1502
Copy link
Contributor

Do you have the invalid image to attach to the PR so we can test in the future?

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Jul 16, 2024
@Saschl
Copy link
Contributor Author

Saschl commented Jul 16, 2024

Do you have the invalid image to attach to the PR so we can test in the future?

Sure! https://drive.google.com/file/d/1pfCPCEJkA_d-glKWOgou3rGbHixA8AK6/view?usp=sharing

@bo0tzz
Copy link
Member

bo0tzz commented Jul 16, 2024

What is the reason for making this configurable/not defaulting it to on?

@Saschl
Copy link
Contributor Author

Saschl commented Jul 16, 2024

What is the reason for making this configurable/not defaulting it to on?

It seems like that having it on by default could cause issues like: #10452

@alextran1502
Copy link
Contributor

I tried to drop the file you posted into the instance. Of course, the thumbnail doesn't get generated, but it doesn't seem to crash the instance.

@Saschl
Copy link
Contributor Author

Saschl commented Jul 16, 2024

I tried to drop the file you posted into the instance. Of course, the thumbnail doesn't get generated, but it doesn't seem to crash the instance.

Exactly, and with failOn: none the thumbnails are being generated. The fear is only that there might be images then that could cause crashes I believe

@mertalev
Copy link
Contributor

mertalev commented Jul 16, 2024

It isn't guaranteed that an invalid image crashes the server, but there's a higher risk if it's routed to a foreign loader like ImageMagick, libraw or libheif. I've had it happen for a HEIF image in the past and it went away when I changed this setting to fail on error. The default is actually to fail on warning.

@mertalev mertalev merged commit d37e8ed into immich-app:main Jul 18, 2024
23 checks passed
@Saschl Saschl deleted the feat/invalid-image-env branch July 21, 2024 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation 🗄️server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants