[ENG-828, ENG-633] Fix corrupt videos force crashing the app (#1028)

* fix corrupt videos crashing the app

* fix typo

* self-proclaimed genius
This commit is contained in:
jake 2023-06-27 06:04:40 +01:00 committed by GitHub
parent ac5f6323a5
commit 0dae7f7a63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 2 deletions

View file

@ -12,9 +12,9 @@ edition = { workspace = true }
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
ffmpeg-sys-next = "6.0.0"
ffmpeg-sys-next = "6.0.1"
thiserror = "1.0.37"
thiserror = "1.0.40"
webp = "0.2.2"
tokio = { workspace = true, features = ["fs", "rt"] }

View file

@ -36,6 +36,10 @@ pub enum ThumbnailerError {
InvalidQuality(f32),
#[error("Background task failed: {0}")]
BackgroundTaskFailed(#[from] JoinError),
#[error("The video is most likely corrupt and will be skipped")]
CorruptVideo,
#[error("The video file contains subtitles and will be skipped")]
Subtitles,
}
/// Enum to represent possible errors from FFmpeg library

View file

@ -101,6 +101,17 @@ impl MovieDecoder {
}
}
unsafe {
if (*decoder.format_context).probe_score == 100 {
return Err(ThumbnailerError::CorruptVideo);
}
// TODO(brxken128): idk if this is needed but i think so
if (*decoder.format_context).subtitle_codec_id == AVCodecID::AV_CODEC_ID_NONE {
return Err(ThumbnailerError::Subtitles);
}
}
decoder.initialize_video(prefer_embedded_metadata)?;
decoder.frame = unsafe { av_frame_alloc() };