From b1061fe90ace1a1dedce41e94b7dec807325f60a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Thu, 4 Jul 2019 14:57:23 +0300 Subject: [PATCH] sodiumdecrypter: Ensure to pull enough data from upstream if not starting on a chunk boundary We round down to the previous chunk boundary, but then we also have to add the difference between the offset of that chunk to the requested offset to the size of the buffer that is pulled from upstream. Otherwise there will be an unneeded short read, which could cause downstream to EOS too early. --- gst-plugin-sodium/src/decrypter.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/gst-plugin-sodium/src/decrypter.rs b/gst-plugin-sodium/src/decrypter.rs index 42a13624..3205797f 100644 --- a/gst-plugin-sodium/src/decrypter.rs +++ b/gst-plugin-sodium/src/decrypter.rs @@ -538,19 +538,26 @@ impl Decrypter { let chunk_index = offset as u64 / block_size as u64; gst_debug!(CAT, obj: pad, "Stream Block index: {}", chunk_index); - let buffer = - self.pull_requested_buffer(pad, element, requested_size, block_size, chunk_index)?; + let pull_offset = offset - (chunk_index * block_size as u64); + assert!(pull_offset <= std::u32::MAX as u64); + let pull_offset = pull_offset as u32; + + let buffer = self.pull_requested_buffer( + pad, + element, + requested_size + pull_offset, + block_size, + chunk_index, + )?; let mut state = self.state.lock().unwrap(); // This will only be run after READY state, // and will be guaranted to be initialized let state = state.as_mut().unwrap(); - let adapter_offset = offset - (chunk_index * block_size as u64); - assert!(adapter_offset <= std::usize::MAX as u64); - let adapter_offset = adapter_offset as usize; - state.decrypt_into_adapter(element, &self.srcpad, &buffer, chunk_index)?; + + let adapter_offset = pull_offset as usize; state.get_requested_buffer(&self.srcpad, requested_size, adapter_offset) } }