@@ -17,6 +17,7 @@ pub enum SpsError {
17
17
ReaderError ( bitreader:: BitReaderError ) ,
18
18
RbspReaderError ( RbspBitReaderError ) ,
19
19
PicOrderCnt ( PicOrderCntError ) ,
20
+ ScalingMatrix ( ScalingMatrixError ) ,
20
21
/// log2_max_frame_num_minus4 must be between 0 and 12
21
22
Log2MaxFrameNumMinus4OutOfRange ( u32 ) ,
22
23
BadSeqParamSetId ( ParamSetIdError ) ,
@@ -286,14 +287,17 @@ pub struct ScalingList {
286
287
// TODO
287
288
}
288
289
impl ScalingList {
289
- pub fn read ( r : & mut RbspBitReader < ' _ > , size : u8 ) -> Result < ScalingList , bitreader :: BitReaderError > {
290
+ pub fn read ( r : & mut RbspBitReader < ' _ > , size : u8 ) -> Result < ScalingList , ScalingMatrixError > {
290
291
let mut scaling_list = vec ! ( ) ;
291
292
let mut last_scale = 8 ;
292
293
let mut next_scale = 8 ;
293
294
let mut _use_default_scaling_matrix_flag = false ;
294
295
for j in 0 ..size {
295
296
if next_scale != 0 {
296
297
let delta_scale = r. read_se ( ) ?;
298
+ if delta_scale < -128 || delta_scale > 127 {
299
+ return Err ( ScalingMatrixError :: DeltaScaleOutOfRange ( delta_scale) ) ;
300
+ }
297
301
next_scale = ( last_scale + delta_scale + 256 ) % 256 ;
298
302
_use_default_scaling_matrix_flag = j == 0 && next_scale == 0 ;
299
303
}
@@ -304,6 +308,20 @@ impl ScalingList {
304
308
Ok ( ScalingList { } )
305
309
}
306
310
}
311
+
312
+ #[ derive( Debug , PartialEq ) ]
313
+ pub enum ScalingMatrixError {
314
+ ReaderError ( bitreader:: BitReaderError ) ,
315
+ /// The `delta_scale` field must be between -128 and 127 inclusive.
316
+ DeltaScaleOutOfRange ( i32 ) ,
317
+ }
318
+
319
+ impl From < bitreader:: BitReaderError > for ScalingMatrixError {
320
+ fn from ( e : bitreader:: BitReaderError ) -> Self {
321
+ ScalingMatrixError :: ReaderError ( e)
322
+ }
323
+ }
324
+
307
325
#[ derive( Debug , Clone ) ]
308
326
pub struct SeqScalingMatrix {
309
327
// TODO
@@ -314,7 +332,7 @@ impl Default for SeqScalingMatrix {
314
332
}
315
333
}
316
334
impl SeqScalingMatrix {
317
- fn read ( r : & mut RbspBitReader < ' _ > , chroma_format_idc : u32 ) -> Result < SeqScalingMatrix , bitreader :: BitReaderError > {
335
+ fn read ( r : & mut RbspBitReader < ' _ > , chroma_format_idc : u32 ) -> Result < SeqScalingMatrix , ScalingMatrixError > {
318
336
let mut scaling_list4x4 = vec ! ( ) ;
319
337
let mut scaling_list8x8 = vec ! ( ) ;
320
338
@@ -376,7 +394,7 @@ impl ChromaInfo {
376
394
fn read_scaling_matrix ( r : & mut RbspBitReader < ' _ > , chroma_format_idc : u32 ) -> Result < SeqScalingMatrix , SpsError > {
377
395
let scaling_matrix_present_flag = r. read_bool ( ) ?;
378
396
if scaling_matrix_present_flag {
379
- SeqScalingMatrix :: read ( r, chroma_format_idc) . map_err ( |e| e . into ( ) )
397
+ SeqScalingMatrix :: read ( r, chroma_format_idc) . map_err ( SpsError :: ScalingMatrix )
380
398
} else {
381
399
Ok ( SeqScalingMatrix :: default ( ) )
382
400
}
0 commit comments