diff --git a/libbz2-rs-sys/src/allocator.rs b/libbz2-rs-sys/src/allocator.rs index 1347a822d..8828896fd 100644 --- a/libbz2-rs-sys/src/allocator.rs +++ b/libbz2-rs-sys/src/allocator.rs @@ -106,7 +106,20 @@ pub(crate) mod c_allocator { pub(crate) static ALLOCATOR: (AllocFunc, FreeFunc) = (self::allocate, self::deallocate); unsafe extern "C" fn allocate(_opaque: *mut c_void, count: c_int, size: c_int) -> *mut c_void { - unsafe { libc::malloc((count * size) as usize) } + // NOTE: allocations bigger than isize::MAX are UB in LLVM. + let (Ok(count), Ok(size)) = (isize::try_from(count), isize::try_from(size)) else { + return core::ptr::null_mut(); + }; + + let Some(len) = count.checked_mul(size) else { + return core::ptr::null_mut(); + }; + + let Ok(len) = usize::try_from(len) else { + return core::ptr::null_mut(); + }; + + unsafe { libc::malloc(len) } } unsafe extern "C" fn deallocate(_opaque: *mut c_void, ptr: *mut c_void) { diff --git a/libbz2-rs-sys/src/bzlib.rs b/libbz2-rs-sys/src/bzlib.rs index 59b6fa4de..3c22f6ed3 100644 --- a/libbz2-rs-sys/src/bzlib.rs +++ b/libbz2-rs-sys/src/bzlib.rs @@ -87,7 +87,7 @@ macro_rules! prefix { pub(crate) use prefix; -/// The version of the zlib library. +/// The version of the libbzip2-rs-sys library. /// /// Its value is a pointer to a NULL-terminated sequence of bytes. /// @@ -95,8 +95,8 @@ pub(crate) use prefix; #[doc = libbz2_rs_sys_version!()] /// `: /// -/// - The first component is the version of stock zlib that this release is compatible with -/// - The final component is the zlib-rs version used to build this release. +/// - The first component is the version of stock bzip2 that this release is compatible with +/// - The final component is the libbzip2-rs-sys version used to build this release. #[cfg_attr(feature = "export-symbols", export_name = prefix!(BZ2_bzlibVersion))] #[cfg(feature = "stdio")] pub const extern "C" fn BZ2_bzlibVersion() -> *const core::ffi::c_char { @@ -1058,7 +1058,7 @@ impl TryFrom for Action { /// - after [`BZ2_bzCompressEnd`] /// - [`BZ_PARAM_ERROR`] if any of /// - `strm.is_null()` -/// - `strm.s.is_null()` +/// - `strm.state.is_null()` /// - action is not one of [`BZ_RUN`], [`BZ_FLUSH`] or [`BZ_FINISH`] /// - [`BZ_RUN_OK`] successfully compressed, but ran out of input or output space /// - [`BZ_FLUSH_OK`] not all compressed data has been written to the output yet @@ -1173,7 +1173,7 @@ fn compress_loop(strm: &mut BzStream, s: &mut EState, action: i32) -> Re /// /// - [`BZ_PARAM_ERROR`] if any of /// - `strm.is_null()` -/// - `strm.s.is_null()` +/// - `strm.state.is_null()` /// - no [valid allocator](bz_stream#custom-allocators) could be configured /// - [`BZ_OK`] otherwise /// @@ -1596,7 +1596,7 @@ pub(crate) fn index_into_f(index: u32, cftab: &[u32; 257]) -> u8 { macro_rules! GET_LL4 { ($s:expr, $i:expr) => { - $s.ll4.as_slice()[($s.tPos >> 1) as usize] as u32 >> ($s.tPos << 2 & 0x4) & 0xf + $s.ll4.as_slice()[($s.tPos >> 1) as usize] as u32 >> ($i << 2 & 0x4) & 0xf }; } @@ -1766,7 +1766,7 @@ fn un_rle_obuf_to_output_small(strm: &mut BzStream, s: &mut DState) -> b /// /// - [`BZ_PARAM_ERROR`] if any of /// - `strm.is_null()` -/// - `strm.s.is_null()` +/// - `strm.state.is_null()` /// - `strm.avail_out < 1` /// - [`BZ_DATA_ERROR`] if a data integrity error is detected in the compressed stream /// - [`BZ_DATA_ERROR_MAGIC`] if the compressed stream doesn't begin with the right magic bytes @@ -1879,7 +1879,7 @@ pub(crate) fn BZ2_bzDecompressHelp(strm: &mut BzStream) -> ReturnCode { /// /// - [`BZ_PARAM_ERROR`] if any of /// - `strm.is_null()` -/// - `strm.s.is_null()` +/// - `strm.state.is_null()` /// - no [valid allocator](bz_stream#custom-allocators) could be configured /// - [`BZ_OK`] otherwise ///