Merge pull request #102 from BeatButton/write-image-blob-null

don't segfault if MagickGetImageBlob returns null
This commit is contained in:
Nathan Fiedler
2023-04-07 11:31:08 -07:00
committed by GitHub

View File

@ -831,13 +831,17 @@ impl MagickWand {
bindings::MagickSetImageFormat(self.wand, c_format.as_ptr()); bindings::MagickSetImageFormat(self.wand, c_format.as_ptr());
bindings::MagickGetImageBlob(self.wand, &mut length) bindings::MagickGetImageBlob(self.wand, &mut length)
}; };
let mut bytes = Vec::with_capacity(length as usize); if blob.is_null() {
unsafe { Err(MagickError("failed to write image blob"))
bytes.set_len(length as usize); } else {
ptr::copy_nonoverlapping(blob, bytes.as_mut_ptr(), length as usize); let mut bytes = Vec::with_capacity(length as usize);
bindings::MagickRelinquishMemory(blob as *mut c_void); unsafe {
}; bytes.set_len(length as usize);
Ok(bytes) ptr::copy_nonoverlapping(blob, bytes.as_mut_ptr(), length as usize);
bindings::MagickRelinquishMemory(blob as *mut c_void);
};
Ok(bytes)
}
} }
/// Write the images in the desired format to a new blob. /// Write the images in the desired format to a new blob.