Skip to content

Commit

Permalink
Fix ffprobe duration conversion panics
Browse files Browse the repository at this point in the history
rust-lang/rust#83400 would be useful
  • Loading branch information
alexheretic committed Dec 2, 2022
1 parent 60c18a4 commit b4acad0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions 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.
Expand Down
16 changes: 14 additions & 2 deletions 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 {
Expand Down Expand Up @@ -95,7 +95,19 @@ fn read_duration(probe: &ffprobe::FfProbe) -> anyhow::Result<Duration> {
Some(duration_s) => {
let duration_f = duration_s
.parse::<f64>()
.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),
Expand Down

0 comments on commit b4acad0

Please sign in to comment.