Skip to content

Commit

Permalink
Fix undefined behavior in VP9Decoder::decode()
Browse files Browse the repository at this point in the history
In VP9Decoder::decode(), if vpx_codec_decode() fails and `private` is
None, we attempt to construct a Box via Box::from_raw() from a NULL
pointer, which is undefined behavior.
  • Loading branch information
00xc authored and lu-zero committed Feb 28, 2024
1 parent dca2a43 commit 7d746a4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ impl<T> VP9Decoder<T> {
match ret {
VPX_CODEC_OK => Ok(()),
_ => {
let _ = unsafe { Box::from_raw(priv_data) };
if !priv_data.is_null() {
let _ = unsafe { Box::from_raw(priv_data) };
}
Err(ret)
}
}
Expand Down

0 comments on commit 7d746a4

Please sign in to comment.