From 04136b6cc10d6a596e4c096e53ad06bdce2f26bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Sat, 16 Sep 2023 10:59:27 +0300 Subject: [PATCH] onvifmetadataparse: Skip metadata frames with unrepresentable UTC time Previously we would panic, which causes the element to post an error message. Instead, simply skip metadata frames if their UTC time since the UNIX epoch can't be represented as nanoseconds in u64. Part-of: --- net/onvif/Cargo.toml | 2 +- net/onvif/src/onvifmetadataparse/imp.rs | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/net/onvif/Cargo.toml b/net/onvif/Cargo.toml index 25160d56..1f175b47 100644 --- a/net/onvif/Cargo.toml +++ b/net/onvif/Cargo.toml @@ -15,7 +15,7 @@ gst-base = { package = "gstreamer-base", git = "https://gitlab.freedesktop.org/g gst-video = { package = "gstreamer-video", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs", branch = "0.19", version = "0.19", features = ["v1_20"] } once_cell = "1.0" xmlparser = "0.13" -chrono = { version = "0.4", default-features = false } +chrono = { version = "0.4.31", default-features = false } cairo-rs = { git = "https://github.com/gtk-rs/gtk-rs-core", branch = "0.16", version = "0.16", features=["use_glib"] } pango = { git = "https://github.com/gtk-rs/gtk-rs-core", branch = "0.16", version = "0.16" } pangocairo = { git = "https://github.com/gtk-rs/gtk-rs-core", branch = "0.16", version = "0.16" } diff --git a/net/onvif/src/onvifmetadataparse/imp.rs b/net/onvif/src/onvifmetadataparse/imp.rs index 2e138d54..3ec0991b 100644 --- a/net/onvif/src/onvifmetadataparse/imp.rs +++ b/net/onvif/src/onvifmetadataparse/imp.rs @@ -219,12 +219,12 @@ impl OnvifMetadataParse { Some(diff) => diff, None => { gst::error!( - CAT, - obj: pad, - "Too big running time difference between initial running time {:?} and current running time {:?}", - initial_running_time, - running_time, - ); + CAT, + obj: pad, + "Too big running time difference between initial running time {:?} and current running time {:?}", + initial_running_time, + running_time, + ); return Err(gst::FlowError::Error); } }; @@ -359,8 +359,17 @@ impl OnvifMetadataParse { gst::FlowError::Error })?; - let dt_unix_ns = - (dt.timestamp_nanos() as u64).nseconds() + crate::PRIME_EPOCH_OFFSET; + let dt_unix_ns = dt + .timestamp_nanos_opt() + .and_then(|ns| u64::try_from(ns).ok()) + .and_then(|ns| ns.nseconds().checked_add(crate::PRIME_EPOCH_OFFSET)); + + let dt_unix_ns = if let Some(dt_unix_ns) = dt_unix_ns { + dt_unix_ns + } else { + gst::warning!(CAT, imp: self, "Frame with unrepresentable UTC time {}", dt,); + continue; + }; gst::trace!( CAT,