Skip to content
Merged
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
11 changes: 11 additions & 0 deletions src/batch_cuda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ impl CudaBatchCompressor {
let offset = output_offsets[i] as usize;
let size = size as usize;

// Security: Validate GPU output sizes to prevent panics or OOB access
if offset.checked_add(size).ok_or("Integer overflow in offset calculation")? > total_output_bound {
return Err("GPU returned invalid compressed size (buffer overflow)".into());
}

// Double check against expected bound
let expected_bound = crate::compress::Compressor::deflate_compress_bound(inputs[i].len());
if size > expected_bound {
return Err("GPU returned invalid compressed size (exceeds bound)".into());
}

let slice = dev_output.slice(offset..offset + size);
let host_data = self.device.dtoh_sync_copy(&slice)?;
results.push(host_data);
Expand Down
Loading