From 2656ec18af13806a3ed9cb9bbf7d62a519f947b4 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Tue, 5 Nov 2024 16:57:16 +0100 Subject: [PATCH 1/2] chore(image): ignore invalid images files / formats --- app/jobs/image_processor_job.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/jobs/image_processor_job.rb b/app/jobs/image_processor_job.rb index aa39a687e..f112d9fc3 100644 --- a/app/jobs/image_processor_job.rb +++ b/app/jobs/image_processor_job.rb @@ -14,6 +14,10 @@ class ImageProcessorJob < ApplicationJob # (to avoid modifying the file while it is being scanned). retry_on FileNotScannedYetError, wait: :exponentially_longer, attempts: 10 + # Usually invalid image or ImageMagick decoder blocked for this format + retry_on MiniMagick::Invalid, attempts: 3 + retry_on MiniMagick::Error, attempts: 3 + rescue_from ActiveStorage::PreviewError do retry_or_discard end @@ -82,12 +86,8 @@ class ImageProcessorJob < ApplicationJob end def retry_or_discard - if executions < max_attempts + if executions < 3 retry_job wait: 5.minutes end end - - def max_attempts - 3 - end end From e2f3f236de5e29a41ee71a11e7c982aa8aac5610 Mon Sep 17 00:00:00 2001 From: Colin Darie Date: Tue, 5 Nov 2024 16:57:59 +0100 Subject: [PATCH 2/2] chore(image): don't try to process empty images --- app/models/concerns/attachment_image_processor_concern.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/concerns/attachment_image_processor_concern.rb b/app/models/concerns/attachment_image_processor_concern.rb index cd0e3ff65..921d1c5bf 100644 --- a/app/models/concerns/attachment_image_processor_concern.rb +++ b/app/models/concerns/attachment_image_processor_concern.rb @@ -21,6 +21,7 @@ module AttachmentImageProcessorConcern return if blob.attachments.size != 1 return if blob.attachments.last.record_type == "Export" return if !blob.content_type.in?(PROCESSABLE_TYPES) + return if blob.byte_size.zero? # some empty files may be considered as image depending on filename ImageProcessorJob.perform_later(blob) end