FIX: Ignore invalid images when shrinking uploads (#25346)

This commit is contained in:
Jarek Radosz 2024-01-22 12:10:29 +01:00 committed by GitHub
parent ae2d9de164
commit 5278734fe2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View File

@ -40,7 +40,11 @@ class ShrinkUploadedImage
return false return false
end end
w, h = FastImage.size(path, timeout: 15, raise_on_failure: true) begin
w, h = FastImage.size(path, timeout: 15, raise_on_failure: true)
rescue FastImage::SizeNotFound
return false
end
if !w || !h if !w || !h
log "Invalid image dimensions after resizing" log "Invalid image dimensions after resizing"

View File

@ -110,6 +110,21 @@ RSpec.describe ShrinkUploadedImage do
expect(result).to be(false) expect(result).to be(false)
end end
it "returns false if the image is invalid" do
post = Fabricate(:post, raw: "<img src='#{upload.url}'>")
post.link_post_uploads
FastImage.stubs(:size).raises(FastImage::SizeNotFound.new)
result =
ShrinkUploadedImage.new(
upload: upload,
path: Discourse.store.path_for(upload),
max_pixels: 10_000,
).perform
expect(result).to be(false)
end
end end
context "when S3 uploads are enabled" do context "when S3 uploads are enabled" do