Skip to content

Commit 054f99b

Browse files
michielp1807folkertdev
authored andcommitted
Use checked_add instead of manual check
The integer types are specified in this exact way to match the C implementation
1 parent 795d438 commit 054f99b

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

lib/decompress/zstd_decompress.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,19 +1216,18 @@ unsafe fn readSkippableFrameSize(src: *const core::ffi::c_void, srcSize: size_t)
12161216
}
12171217

12181218
fn read_skippable_frame_size(src: &[u8]) -> Result<size_t, Error> {
1219-
let skippableHeaderSize = ZSTD_SKIPPABLEHEADERSIZE as usize;
1219+
let skippableHeaderSize = ZSTD_SKIPPABLEHEADERSIZE as u32;
12201220

12211221
let [_, _, _, _, a, b, c, d, ..] = *src else {
12221222
return Err(Error::srcSize_wrong);
12231223
};
12241224

12251225
let size = u32::from_le_bytes([a, b, c, d]);
12261226

1227-
if size.wrapping_add(8) < size {
1228-
return Err(Error::frameParameter_unsupported);
1229-
}
1227+
let skippableSize = skippableHeaderSize
1228+
.checked_add(size)
1229+
.ok_or(Error::frameParameter_unsupported)? as usize;
12301230

1231-
let skippableSize = skippableHeaderSize.wrapping_add(size as usize);
12321231
if skippableSize > src.len() {
12331232
return Err(Error::srcSize_wrong);
12341233
}

0 commit comments

Comments
 (0)