Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure that there is room for length header in byte array #18

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions wasm-thumbnail/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ pub extern "C" fn resize_and_pad(
let slice: &[u8] = unsafe { std::slice::from_raw_parts(pointer, length) };

let mut out: Cursor<Vec<u8>> = Cursor::new(Vec::with_capacity(nsize));
// Reserve space at the start for length header
let _ = out.write_all(&[0,0,0,0]);
// Add additional space at the start for the length header
out.get_mut().extend_from_slice(&[0,0,0,0]);

match _resize_and_pad(slice, &mut out, nwidth, nheight, nsize, nquality) {
Ok(thumbnail_len) => {
out.get_mut().splice(..4, thumbnail_len.to_be_bytes().iter().cloned());
out.get_mut()[0..4].copy_from_slice(&thumbnail_len.to_be_bytes());
}
_ => {
panic!("Image too large")
Expand Down Expand Up @@ -95,4 +95,4 @@ pub extern "C" fn deallocate(pointer: *mut c_void, capacity: usize) {
unsafe {
let _ = Vec::from_raw_parts(pointer, 0, capacity);
}
}
}
Loading