From 97e6a89cac2992c27fb9dc341a10b0b5dadbb24b Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Wed, 24 Nov 2021 13:57:15 +0100 Subject: [PATCH] aws_transcriber: sanity check alternative length The design of the element is based on the assumption that when receiving a partial result, the following result will contain at least as many items as there were stable items in the previous result. This patch adds a sanity check to make sure our "partial index" isn't larger than the new received result, and errors out otherwise. partial_index will eventually be reset to 0 once we receive a new non-partial result. --- net/rusoto/src/aws_transcriber/imp.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/net/rusoto/src/aws_transcriber/imp.rs b/net/rusoto/src/aws_transcriber/imp.rs index 2b111f17..cac7d7e3 100644 --- a/net/rusoto/src/aws_transcriber/imp.rs +++ b/net/rusoto/src/aws_transcriber/imp.rs @@ -379,6 +379,22 @@ impl Transcriber { ) { let lateness = self.settings.lock().unwrap().lateness; + if alternative.items.len() <= state.partial_index { + gst_error!( + CAT, + obj: element, + "sanity check failed, alternative length {} < partial_index {}", + alternative.items.len(), + state.partial_index + ); + + if !partial { + state.partial_index = 0; + } + + return; + } + for item in &alternative.items[state.partial_index..] { let start_time = gst::ClockTime::from_nseconds((item.start_time as f64 * 1_000_000_000.0) as u64)