media assets: track corrupted files in media metadata.

If a media asset is corrupt, include the error message from libvips or
ffmpeg in the "Vips:Error" or "FFmpeg:Error" fields in the media
metadata table.

Corrupt files can't be uploaded nowadays, but they could be in the past,
so we have some old corrupted files that we can't generate thumbnails
for. This lets us mark these files in the metadata so they're findable
with the tag search `exif:Vips:Error`.

Known bug: Vips has a single global error buffer that is shared between
threads and that isn't cleared between operations. So we can't reliably
get the actual error message because it may pick up errors from other
threads, or from previous operations in the same thread.
This commit is contained in:
evazion
2022-11-02 14:55:07 -05:00
parent 19c091d81c
commit 3172031caa
7 changed files with 68 additions and 33 deletions

View File

@@ -467,10 +467,11 @@ class MediaFileTest < ActiveSupport::TestCase
@metadata = @file.metadata
assert_equal(true, @file.is_corrupt?)
assert_equal("libvips error", @file.error)
assert_equal([475, 600], @file.dimensions)
assert_equal("File format error", @metadata["ExifTool:Error"])
assert_equal("89a", @metadata["GIF:GIFVersion"])
assert_equal(9, @metadata.count)
assert_equal(10, @metadata.count)
end
should "not raise an exception when reading the frame count" do
@@ -478,11 +479,12 @@ class MediaFileTest < ActiveSupport::TestCase
@metadata = @file.metadata
assert_equal(true, @file.is_corrupt?)
assert_equal("libvips error", @file.error)
assert_equal(nil, @file.frame_count)
assert_equal([575, 800], @file.dimensions)
assert_equal("File format error", @metadata["ExifTool:Error"])
assert_equal("89a", @metadata["GIF:GIFVersion"])
assert_equal(9, @metadata.count)
assert_equal(10, @metadata.count)
assert_nothing_raised { @file.attributes }
end
end
@@ -493,8 +495,9 @@ class MediaFileTest < ActiveSupport::TestCase
@metadata = @file.metadata
assert_equal(true, @file.is_corrupt?)
assert_equal("libvips error", @file.error)
assert_equal("Grayscale", @metadata["PNG:ColorType"])
assert_equal(9, @metadata.count)
assert_equal(10, @metadata.count)
end
end
@@ -504,8 +507,9 @@ class MediaFileTest < ActiveSupport::TestCase
@metadata = @file.metadata
assert_equal(true, @file.is_corrupt?)
assert_equal("libvips error", @file.error)
assert_equal(1, @metadata["File:ColorComponents"])
assert_equal(10, @metadata.count)
assert_equal(11, @metadata.count)
end
end