Skip to content

Commit

Permalink
Input check in FFI
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Oct 12, 2023
1 parent 5a2ef3e commit f4eafe7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion imagequant-sys/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,9 @@ pub unsafe extern "C" fn liq_histogram_add_colors(input_hist: &mut liq_histogram
bad_object!(input_hist, LIQ_HISTOGRAM_MAGIC) { return Error::InvalidPointer; }
let input_hist = &mut input_hist.inner;

if num_entries < 0 {
return Error::ValueOutOfRange;
}
if num_entries == 0 {
return LIQ_OK;
}
Expand All @@ -638,9 +641,10 @@ pub extern "C" fn liq_histogram_add_image(input_hist: &mut liq_histogram, attr:
input_hist.add_image(attr, input_image).err().unwrap_or(LIQ_OK)
}

/// This is just to exist in backtraces of crashes that aren't mine
#[no_mangle]
#[inline(never)]
pub unsafe fn liq_executing_user_callback(callback: liq_image_get_rgba_row_callback, temp_row: &mut [MaybeUninit<liq_color>], row: usize, user_info: AnySyncSendPtr) {
pub unsafe extern "Rust" fn liq_executing_user_callback(callback: liq_image_get_rgba_row_callback, temp_row: &mut [MaybeUninit<liq_color>], row: usize, user_info: AnySyncSendPtr) {
callback(temp_row.as_mut_ptr(), row as _, temp_row.len() as _, user_info);
}

Expand Down

0 comments on commit f4eafe7

Please sign in to comment.