mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-26 03:21:03 +00:00
gstreamer: bufferlist: Check for out of range indices before trying to get buffer
Passing an index bigger than the length will cause an assertion in the C function. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1444>
This commit is contained in:
parent
1b537c17c8
commit
9f151466b7
1 changed files with 12 additions and 11 deletions
|
@ -50,20 +50,22 @@ impl BufferListRef {
|
||||||
#[doc(alias = "gst_buffer_list_get")]
|
#[doc(alias = "gst_buffer_list_get")]
|
||||||
pub fn get(&self, idx: u32) -> Option<&BufferRef> {
|
pub fn get(&self, idx: u32) -> Option<&BufferRef> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = ffi::gst_buffer_list_get(self.as_mut_ptr(), idx);
|
if idx as usize >= self.len() {
|
||||||
if ptr.is_null() {
|
return None;
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(BufferRef::from_ptr(ptr))
|
|
||||||
}
|
}
|
||||||
|
let ptr = ffi::gst_buffer_list_get(self.as_mut_ptr(), idx);
|
||||||
|
Some(BufferRef::from_ptr(ptr))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(alias = "gst_buffer_list_get")]
|
#[doc(alias = "gst_buffer_list_get")]
|
||||||
pub fn get_owned(&self, idx: u32) -> Option<Buffer> {
|
pub fn get_owned(&self, idx: u32) -> Option<Buffer> {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
if idx as usize >= self.len() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
let ptr = ffi::gst_buffer_list_get(self.as_mut_ptr(), idx);
|
let ptr = ffi::gst_buffer_list_get(self.as_mut_ptr(), idx);
|
||||||
from_glib_none(ptr)
|
Some(from_glib_none(ptr))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,12 +73,11 @@ impl BufferListRef {
|
||||||
#[doc(alias = "get_writable")]
|
#[doc(alias = "get_writable")]
|
||||||
pub fn get_mut(&mut self, idx: u32) -> Option<&mut BufferRef> {
|
pub fn get_mut(&mut self, idx: u32) -> Option<&mut BufferRef> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = ffi::gst_buffer_list_get_writable(self.as_mut_ptr(), idx);
|
if idx as usize >= self.len() {
|
||||||
if ptr.is_null() {
|
return None;
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(BufferRef::from_mut_ptr(ptr))
|
|
||||||
}
|
}
|
||||||
|
let ptr = ffi::gst_buffer_list_get_writable(self.as_mut_ptr(), idx);
|
||||||
|
Some(BufferRef::from_mut_ptr(ptr))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue