From 8dd9dff5dd1b67717c68b02cc2dc28944b561008 Mon Sep 17 00:00:00 2001 From: Jakub Stasiak Date: Thu, 5 Mar 2020 20:09:15 +0100 Subject: [PATCH] Drop Chunk::from_wav_buffer(), it's unsound Mix_QuickLoad_WAV performs buffer traversal assuming we passed it enough data. This is not necessarily true and protecting against it would duplicate some of the Mix_QuickLoad_WAV logic here. As this is less useful than from_raw_buffer() let's drop it for now. --- src/sdl2/mixer/mod.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/sdl2/mixer/mod.rs b/src/sdl2/mixer/mod.rs index 728e1a0c..7afb91fe 100644 --- a/src/sdl2/mixer/mod.rs +++ b/src/sdl2/mixer/mod.rs @@ -232,10 +232,9 @@ impl Drop for Chunk { fn drop(&mut self) { if self.owned { unsafe { - // Mix_QuickLoad_* functions don't set the allocated flag, but - // from_wav_buffer and from_raw_buffer *do* take ownership of the data, - // so we need to deallocate the buffers here, because Mix_FreeChunk won't - // and we'd be leaking memory otherwise. + // Mix_QuickLoad_* functions don't set the allocated flag, but from_raw_buffer + // *does* take ownership of the data, so we need to deallocate the buffers here, + // because Mix_FreeChunk won't and we'd be leaking memory otherwise. if (*self.raw).allocated == 0 { drop(Box::from_raw((*self.raw).abuf)); } @@ -252,13 +251,6 @@ impl Chunk { Self::from_owned_raw(raw) } - /// Get chunk based on a buffer containing WAV data in the mixer format. The chunk takes - /// ownership of the buffer. - pub fn from_wav_buffer(buffer: Box<[u8]>) -> Result { - let raw = unsafe { mixer::Mix_QuickLoad_WAV(Box::into_raw(buffer) as *mut u8) }; - Self::from_owned_raw(raw) - } - /// Load chunk from a buffer containing raw audio data in the mixer format. The length of the /// buffer has to fit in 32-bit unsigned integer. The chunk takes ownership of the buffer. ///