@@ -172,6 +172,8 @@ pub fn dequantize_and_idct_block_8x8(
172
172
173
173
let data_with_offset = i16x8_add_sat ( data[ i] , i16x8_splat ( OFFSET + ROUNDING_BIAS ) ) ;
174
174
175
+ // SAFETY: the assert at the start of this function ensures
176
+ // `output_linestride * i + 7` < output.len(), so all accesses are in-bounds.
175
177
unsafe {
176
178
v128_store64_lane :: < 0 > (
177
179
u8x16_narrow_i16x8 (
@@ -187,6 +189,7 @@ pub fn dequantize_and_idct_block_8x8(
187
189
#[ cfg( target_arch = "wasm32" ) ]
188
190
#[ target_feature( enable = "simd128" ) ]
189
191
pub fn color_convert_line_ycbcr ( y_slice : & [ u8 ] , cb_slice : & [ u8 ] , cr_slice : & [ u8 ] , output : & mut [ u8 ] ) -> usize {
192
+
190
193
assert ! ( output. len( ) % 3 == 0 ) ;
191
194
let num = output. len ( ) / 3 ;
192
195
assert ! ( num <= y_slice. len( ) ) ;
@@ -201,6 +204,8 @@ pub fn color_convert_line_ycbcr(y_slice: &[u8], cb_slice: &[u8], cr_slice: &[u8]
201
204
let y: v128 ;
202
205
let cb: v128 ;
203
206
let cr: v128 ;
207
+ // SAFETY: i is at most `num / 8 - 8`, so the highest v128_load64_zero reads from
208
+ // [num - 8, num). The above asserts ensure this is in-bounds.
204
209
unsafe {
205
210
y = v128_load64_zero ( y_slice. as_ptr ( ) . wrapping_add ( i * 8 ) as * const _ ) ;
206
211
cb = v128_load64_zero ( cb_slice. as_ptr ( ) . wrapping_add ( i * 8 ) as * const _ ) ;
@@ -260,6 +265,8 @@ pub fn color_convert_line_ycbcr(y_slice: &[u8], cb_slice: &[u8], cr_slice: &[u8]
260
265
0 , 0 , 0 , // --, --, --
261
266
0 > ( rg_lanes, b) ; // --
262
267
268
+ // SAFETY: i is at most `output.len() / 24 - 1` so the highest possible write is to
269
+ // `output.len() - 1`.
263
270
unsafe {
264
271
v128_store ( output. as_mut_ptr ( ) . wrapping_add ( 24 * i) as * mut _ , rgb_low) ;
265
272
v128_store64_lane :: < 0 > ( rgb_hi, output. as_mut_ptr ( ) . wrapping_add ( 24 * i + 16 ) as * mut _ ) ;
0 commit comments