diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fd21d1..1c8c438 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# Unreleased (v0.5.2) +* Fix ffprobe duration conversion error scenarios panicking. + # v0.5.1 * Change encoded size prediction logic to estimate video stream size (or image size) only. This should be much more consistent than the previous method. diff --git a/src/ffprobe.rs b/src/ffprobe.rs index 2fe17a8..c49571a 100644 --- a/src/ffprobe.rs +++ b/src/ffprobe.rs @@ -1,6 +1,6 @@ //! ffprobe logic use crate::command::args::PixelFormat; -use anyhow::Context; +use anyhow::{ensure, Context}; use std::{fmt, path::Path, time::Duration}; pub struct Ffprobe { @@ -95,7 +95,19 @@ fn read_duration(probe: &ffprobe::FfProbe) -> anyhow::Result { Some(duration_s) => { let duration_f = duration_s .parse::() - .context("invalid ffprobe video duration")?; + .with_context(|| format!("invalid ffprobe video duration: {duration_s:?}"))?; + ensure!( + duration_f.is_sign_positive(), + "invalid negative ffprobe video duration: {duration_s:?}" + ); + ensure!( + duration_f.is_finite(), + "invalid infinite ffprobe video duration: {duration_s:?}" + ); + ensure!( + duration_f < i64::MAX as f64, + "invalid length ffprobe video duration: {duration_s:?}" + ); Ok(Duration::from_secs_f64(duration_f)) } None => Ok(Duration::ZERO),