From 76d6c024cc1ad010b40a866d00d6396f30baedb1 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 18 Feb 2026 12:30:21 +0000 Subject: [PATCH] Sentinel: Validate GPU compression output sizes Added security validation in `src/batch_cuda.rs` to check output sizes returned by the GPU kernel. This prevents potential buffer overflows or panics (DoS) if the GPU returns corrupted or malicious size values. Verified that `offset + size <= total_output_bound` and `size <= expected_bound`. Co-authored-by: 404Setup <153366651+404Setup@users.noreply.github.com> --- src/batch_cuda.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/batch_cuda.rs b/src/batch_cuda.rs index 3ec2702..f275b5e 100644 --- a/src/batch_cuda.rs +++ b/src/batch_cuda.rs @@ -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);