Skip to content

Commit b2c86a6

Browse files
authored
Merge pull request #232 from 404Setup/sentinel-cuda-validation-7675462695814040533
🛡️ Sentinel: Validate GPU compression output sizes
2 parents 14bf153 + 76d6c02 commit b2c86a6

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/batch_cuda.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ impl CudaBatchCompressor {
120120
let offset = output_offsets[i] as usize;
121121
let size = size as usize;
122122

123+
// Security: Validate GPU output sizes to prevent panics or OOB access
124+
if offset.checked_add(size).ok_or("Integer overflow in offset calculation")? > total_output_bound {
125+
return Err("GPU returned invalid compressed size (buffer overflow)".into());
126+
}
127+
128+
// Double check against expected bound
129+
let expected_bound = crate::compress::Compressor::deflate_compress_bound(inputs[i].len());
130+
if size > expected_bound {
131+
return Err("GPU returned invalid compressed size (exceeds bound)".into());
132+
}
133+
123134
let slice = dev_output.slice(offset..offset + size);
124135
let host_data = self.device.dtoh_sync_copy(&slice)?;
125136
results.push(host_data);

0 commit comments

Comments
 (0)