@@ -32,7 +32,7 @@ use crate::alpha_handle_f16::{premultiply_alpha_rgba_f16, unpremultiply_alpha_rg
3232use crate :: alpha_handle_f32:: { premultiply_alpha_rgba_f32, unpremultiply_alpha_rgba_f32} ;
3333use crate :: alpha_handle_u8:: { premultiply_alpha_rgba, unpremultiply_alpha_rgba} ;
3434use crate :: alpha_handle_u16:: { premultiply_alpha_rgba_u16, unpremultiply_alpha_rgba_u16} ;
35- use crate :: support:: check_image_size_overflow;
35+ use crate :: support:: { check_image_size_overflow, check_image_size_overflow_with_stride } ;
3636use crate :: validation:: { PicScaleBufferMismatch , PicScaleError , try_vec} ;
3737use crate :: { ImageSize , WorkloadStrategy } ;
3838#[ cfg( feature = "nightly_f16" ) ]
@@ -226,6 +226,25 @@ impl<T, const N: usize> ImageStoreMut<'_, T, N> {
226226 return Err ( PicScaleError :: ZeroImageDimensions ) ;
227227 }
228228
229+ if check_image_size_overflow (
230+ self . width ,
231+ self . height ,
232+ self . channels ,
233+ size_of :: < T > ( ) as isize ,
234+ ) {
235+ return Err ( PicScaleError :: SourceImageIsTooLarge ) ;
236+ }
237+
238+ if check_image_size_overflow_with_stride (
239+ self . width ,
240+ self . height ,
241+ self . stride ( ) ,
242+ self . channels ,
243+ size_of :: < T > ( ) as isize ,
244+ ) {
245+ return Err ( PicScaleError :: SourceImageIsTooLarge ) ;
246+ }
247+
229248 let valid_size = self . stride ( ) * ( self . height - 1 ) + self . width * N ;
230249
231250 if self . stride ( ) < self . width * N {
@@ -241,9 +260,6 @@ impl<T, const N: usize> ImageStoreMut<'_, T, N> {
241260 slice_len : self . buffer . borrow ( ) . len ( ) ,
242261 } ) ) ;
243262 }
244- if check_image_size_overflow ( self . width , self . height , self . channels ) {
245- return Err ( PicScaleError :: SourceImageIsTooLarge ) ;
246- }
247263 Ok ( ( ) )
248264 }
249265
@@ -262,6 +278,25 @@ where
262278 return Err ( PicScaleError :: ZeroImageDimensions ) ;
263279 }
264280
281+ if check_image_size_overflow (
282+ self . width ,
283+ self . height ,
284+ self . channels ,
285+ size_of :: < T > ( ) as isize ,
286+ ) {
287+ return Err ( PicScaleError :: DestinationImageIsTooLarge ) ;
288+ }
289+
290+ if check_image_size_overflow_with_stride (
291+ self . width ,
292+ self . height ,
293+ self . stride ( ) ,
294+ self . channels ,
295+ size_of :: < T > ( ) as isize ,
296+ ) {
297+ return Err ( PicScaleError :: DestinationImageIsTooLarge ) ;
298+ }
299+
265300 let valid_size = self . stride ( ) * ( self . height - 1 ) + self . width * N ;
266301
267302 if self . stride ( ) < self . width * N {
@@ -278,10 +313,6 @@ where
278313 } ) ) ;
279314 }
280315
281- if check_image_size_overflow ( self . width , self . height , self . channels ) {
282- return Err ( PicScaleError :: DestinationImageIsTooLarge ) ;
283- }
284-
285316 Ok ( ( ) )
286317 }
287318
0 commit comments