From b12278e33452e2ddf5a8acb862c4f4695d562517 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 | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/net/onvif/Cargo.toml b/net/onvif/Cargo.toml index b7296193..c394b8b8 100644 --- a/net/onvif/Cargo.toml +++ b/net/onvif/Cargo.toml @@ -14,7 +14,7 @@ gst-rtp = { package = "gstreamer-rtp", git = "https://gitlab.freedesktop.org/gst gst-base = { package = "gstreamer-base", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs", features = ["v1_20"] } gst-video = { package = "gstreamer-video", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs", features = ["v1_20"] } 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", features=["use_glib"] } pango = { git = "https://github.com/gtk-rs/gtk-rs-core" } pangocairo = { git = "https://github.com/gtk-rs/gtk-rs-core" } diff --git a/net/onvif/src/onvifmetadataparse/imp.rs b/net/onvif/src/onvifmetadataparse/imp.rs index 5a1b88b5..6416e153 100644 --- a/net/onvif/src/onvifmetadataparse/imp.rs +++ b/net/onvif/src/onvifmetadataparse/imp.rs @@ -359,8 +359,19 @@ 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 Some(dt_unix_ns) = dt_unix_ns else { + gst::warning!(CAT, + imp: self, + "Frame with unrepresentable UTC time {}", + dt, + ); + continue; + }; gst::trace!( CAT,