File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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) ;
You can’t perform that action at this time.
0 commit comments