Skip to content

Commit b4acad0

Browse files
committed
Fix ffprobe duration conversion panics
rust-lang/rust#83400 would be useful
1 parent 60c18a4 commit b4acad0

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Unreleased (v0.5.2)
2+
* Fix ffprobe duration conversion error scenarios panicking.
3+
14
# v0.5.1
25
* Change encoded size prediction logic to estimate video stream size (or image size) only.
36
This should be much more consistent than the previous method.

src/ffprobe.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! ffprobe logic
22
use crate::command::args::PixelFormat;
3-
use anyhow::Context;
3+
use anyhow::{ensure, Context};
44
use std::{fmt, path::Path, time::Duration};
55

66
pub struct Ffprobe {
@@ -95,7 +95,19 @@ fn read_duration(probe: &ffprobe::FfProbe) -> anyhow::Result<Duration> {
9595
Some(duration_s) => {
9696
let duration_f = duration_s
9797
.parse::<f64>()
98-
.context("invalid ffprobe video duration")?;
98+
.with_context(|| format!("invalid ffprobe video duration: {duration_s:?}"))?;
99+
ensure!(
100+
duration_f.is_sign_positive(),
101+
"invalid negative ffprobe video duration: {duration_s:?}"
102+
);
103+
ensure!(
104+
duration_f.is_finite(),
105+
"invalid infinite ffprobe video duration: {duration_s:?}"
106+
);
107+
ensure!(
108+
duration_f < i64::MAX as f64,
109+
"invalid length ffprobe video duration: {duration_s:?}"
110+
);
99111
Ok(Duration::from_secs_f64(duration_f))
100112
}
101113
None => Ok(Duration::ZERO),

0 commit comments

Comments
 (0)