mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 08:14:25 +08:00
FIX: Ignore invalid images when shrinking uploads (#25346)
This commit is contained in:
parent
ae2d9de164
commit
5278734fe2
|
@ -40,7 +40,11 @@ class ShrinkUploadedImage
|
|||
return false
|
||||
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
|
||||
log "Invalid image dimensions after resizing"
|
||||
|
|
|
@ -110,6 +110,21 @@ RSpec.describe ShrinkUploadedImage do
|
|||
|
||||
expect(result).to be(false)
|
||||
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
|
||||
|
||||
context "when S3 uploads are enabled" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user