From 147b0fe6c2e77bef1dca107a89a8b78c4b65e544 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Mon, 11 Nov 2024 14:52:21 -0800 Subject: [PATCH] media: ffmpeg: fix undefined behavior in test_avpacket_drop The AvBufferSource pointer gets converted into a Rust slice, so it is not valid to use a null pointer (even though the length is 0). Return a valid pointer derived from an empty slice instead. BUG=b:365852007 Change-Id: I12930c98241d2d711826c577ae23944ec8d5d93b Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6013082 Reviewed-by: Alexandre Courbot Commit-Queue: Daniel Verkamp --- media/ffmpeg/src/avcodec.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/media/ffmpeg/src/avcodec.rs b/media/ffmpeg/src/avcodec.rs index 14221df624..8cab4db4e3 100644 --- a/media/ffmpeg/src/avcodec.rs +++ b/media/ffmpeg/src/avcodec.rs @@ -1041,7 +1041,6 @@ impl Drop for AvFrame { #[cfg(test)] mod tests { - use std::ptr; use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering; use std::sync::Arc; @@ -1078,7 +1077,7 @@ mod tests { } impl AvBufferSource for DropTestBufferSource { fn as_ptr(&self) -> *const u8 { - ptr::null() + [].as_ptr() } fn len(&self) -> usize {