Commit 10d564a3 authored by Luca Barbato's avatar Luca Barbato Committed by Luca Barbato
Browse files

crav1e: Validate the status_to_str input

parent 77a09a6b
......@@ -8,6 +8,8 @@
extern crate rav1e;
extern crate libc;
extern crate num_traits;
extern crate num_derive;
use std::slice;
use std::sync::Arc;
......@@ -29,7 +31,7 @@ use num_traits::cast::FromPrimitive;
pub struct Frame(Arc<rav1e::Frame<u16>>);
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, FromPrimitive)]
pub enum EncoderStatus {
/// Normal operation
Success = 0,
......@@ -382,6 +384,10 @@ pub unsafe extern "C" fn rav1e_last_status(ctx: *const Context) -> EncoderStatus
/// Return a string matching the EncooderStatus variant.
pub unsafe extern "C" fn rav1e_status_to_str(status: EncoderStatus) -> *mut c_char {
if EncoderStatus::from_i32(std::mem::transmute(status)).is_none() {
return std::ptr::null_mut();
let status = format!("{:?}", status);
let cbuf = CString::new(status).unwrap();
let len = cbuf.as_bytes_with_nul().len();
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment