@@ -35,7 +35,7 @@ use boxes::{BoxType, FourCC};
35
35
mod tests;
36
36
37
37
// Arbitrary buffer size limit used for raw read_bufs on a box.
38
- const BUF_SIZE_LIMIT : usize = 10 * 1024 * 1024 ;
38
+ const BUF_SIZE_LIMIT : u64 = 10 * 1024 * 1024 ;
39
39
40
40
// Max table length. Calculating in worst case for one week long video, one
41
41
// frame per table entry in 30 fps.
@@ -1663,7 +1663,7 @@ fn read_moov<T: Read>(f: &mut BMFFBox<T>, context: &mut MediaContext) -> Result<
1663
1663
}
1664
1664
1665
1665
fn read_pssh < T : Read > ( src : & mut BMFFBox < T > ) -> Result < ProtectionSystemSpecificHeaderBox > {
1666
- let len = src. bytes_left ( ) . try_into ( ) ? ;
1666
+ let len = src. bytes_left ( ) ;
1667
1667
let mut box_content = read_buf ( src, len) ?;
1668
1668
let ( system_id, kid, data) = {
1669
1669
let pssh = & mut Cursor :: new ( box_content. as_slice ( ) ) ;
@@ -1681,8 +1681,8 @@ fn read_pssh<T: Read>(src: &mut BMFFBox<T>) -> Result<ProtectionSystemSpecificHe
1681
1681
}
1682
1682
}
1683
1683
1684
- let data_size = be_u32_with_limit ( pssh) ?. to_usize ( ) ;
1685
- let data = read_buf ( pssh, data_size) ?;
1684
+ let data_size = be_u32_with_limit ( pssh) ?;
1685
+ let data = read_buf ( pssh, data_size. into ( ) ) ?;
1686
1686
1687
1687
( system_id, kid, data)
1688
1688
} ;
@@ -2277,7 +2277,7 @@ fn read_vpcc<T: Read>(src: &mut BMFFBox<T>) -> Result<VPxConfigBox> {
2277
2277
} ;
2278
2278
2279
2279
let codec_init_size = be_u16 ( src) ?;
2280
- let codec_init = read_buf ( src, codec_init_size. to_usize ( ) ) ?;
2280
+ let codec_init = read_buf ( src, codec_init_size. into ( ) ) ?;
2281
2281
2282
2282
// TODO(rillian): validate field value ranges.
2283
2283
Ok ( VPxConfigBox {
@@ -2325,7 +2325,7 @@ fn read_av1c<T: Read>(src: &mut BMFFBox<T>) -> Result<AV1ConfigBox> {
2325
2325
} ;
2326
2326
2327
2327
let config_obus_size = src. bytes_left ( ) ;
2328
- let config_obus = read_buf ( src, config_obus_size. try_into ( ) ? ) ?;
2328
+ let config_obus = read_buf ( src, config_obus_size) ?;
2329
2329
2330
2330
Ok ( AV1ConfigBox {
2331
2331
profile,
@@ -2345,12 +2345,12 @@ fn read_av1c<T: Read>(src: &mut BMFFBox<T>) -> Result<AV1ConfigBox> {
2345
2345
fn read_flac_metadata < T : Read > ( src : & mut BMFFBox < T > ) -> Result < FLACMetadataBlock > {
2346
2346
let temp = src. read_u8 ( ) ?;
2347
2347
let block_type = temp & 0x7f ;
2348
- let length = be_u24 ( src) ?;
2349
- if u64 :: from ( length) > src. bytes_left ( ) {
2348
+ let length = be_u24 ( src) ?. into ( ) ;
2349
+ if length > src. bytes_left ( ) {
2350
2350
return Err ( Error :: InvalidData (
2351
2351
"FLACMetadataBlock larger than parent box" ) ) ;
2352
2352
}
2353
- let data = read_buf ( src, length. to_usize ( ) ) ?;
2353
+ let data = read_buf ( src, length) ?;
2354
2354
Ok ( FLACMetadataBlock {
2355
2355
block_type,
2356
2356
data,
@@ -2632,7 +2632,7 @@ fn read_esds<T: Read>(src: &mut BMFFBox<T>) -> Result<ES_Descriptor> {
2632
2632
// Subtract 4 extra to offset the members of fullbox not accounted for in
2633
2633
// head.offset
2634
2634
let esds_size = src. head . size . checked_sub ( src. head . offset + 4 ) . expect ( "offset invalid" ) ;
2635
- let esds_array = read_buf ( src, esds_size. try_into ( ) ? ) ?;
2635
+ let esds_array = read_buf ( src, esds_size) ?;
2636
2636
2637
2637
let mut es_data = ES_Descriptor :: default ( ) ;
2638
2638
find_descriptor ( & esds_array, & mut es_data) ?;
@@ -2691,7 +2691,7 @@ fn read_dops<T: Read>(src: &mut BMFFBox<T>) -> Result<OpusSpecificBox> {
2691
2691
} else {
2692
2692
let stream_count = src. read_u8 ( ) ?;
2693
2693
let coupled_count = src. read_u8 ( ) ?;
2694
- let channel_mapping = read_buf ( src, output_channel_count. to_usize ( ) ) ?;
2694
+ let channel_mapping = read_buf ( src, output_channel_count. into ( ) ) ?;
2695
2695
2696
2696
Some ( ChannelMappingTable {
2697
2697
stream_count,
@@ -2766,7 +2766,7 @@ fn read_alac<T: Read>(src: &mut BMFFBox<T>) -> Result<ALACSpecificBox> {
2766
2766
}
2767
2767
2768
2768
let length = match src. bytes_left ( ) {
2769
- x @ 24 | x @ 48 => x. try_into ( ) . expect ( "infallible conversion to usize" ) ,
2769
+ x @ 24 | x @ 48 => x,
2770
2770
_ => return Err ( Error :: InvalidData ( "ALACSpecificBox magic cookie is the wrong size" ) ) ,
2771
2771
} ;
2772
2772
let data = read_buf ( src, length) ?;
@@ -2841,7 +2841,7 @@ fn read_video_sample_entry<T: Read>(src: &mut BMFFBox<T>) -> Result<SampleEntry>
2841
2841
return Err ( Error :: InvalidData ( "malformed video sample entry" ) ) ;
2842
2842
}
2843
2843
let avcc_size = b. head . size . checked_sub ( b. head . offset ) . expect ( "offset invalid" ) ;
2844
- let avcc = read_buf ( & mut b. content , avcc_size. try_into ( ) ? ) ?;
2844
+ let avcc = read_buf ( & mut b. content , avcc_size) ?;
2845
2845
debug ! ( "{:?} (avcc)" , avcc) ;
2846
2846
// TODO(kinetik): Parse avcC box? For now we just stash the data.
2847
2847
codec_specific = Some ( VideoCodecSpecific :: AVCConfig ( avcc) ) ;
@@ -2871,7 +2871,7 @@ fn read_video_sample_entry<T: Read>(src: &mut BMFFBox<T>) -> Result<SampleEntry>
2871
2871
// Subtract 4 extra to offset the members of fullbox not
2872
2872
// accounted for in head.offset
2873
2873
let esds_size = b. head . size . checked_sub ( b. head . offset + 4 ) . expect ( "offset invalid" ) ;
2874
- let esds = read_buf ( & mut b. content , esds_size. try_into ( ) ? ) ?;
2874
+ let esds = read_buf ( & mut b. content , esds_size) ?;
2875
2875
codec_specific = Some ( VideoCodecSpecific :: ESDSConfig ( esds) ) ;
2876
2876
}
2877
2877
BoxType :: ProtectionSchemeInfoBox => {
@@ -3156,7 +3156,7 @@ fn read_tenc<T: Read>(src: &mut BMFFBox<T>) -> Result<TrackEncryptionBox> {
3156
3156
let default_constant_iv = match ( default_is_encrypted, default_iv_size) {
3157
3157
( 1 , 0 ) => {
3158
3158
let default_constant_iv_size = src. read_u8 ( ) ?;
3159
- Some ( read_buf ( src, default_constant_iv_size. to_usize ( ) ) ?)
3159
+ Some ( read_buf ( src, default_constant_iv_size. into ( ) ) ?)
3160
3160
} ,
3161
3161
_ => None ,
3162
3162
} ;
@@ -3351,7 +3351,7 @@ fn read_ilst_multiple_u8_data<T: Read>(src: &mut BMFFBox<T>) -> Result<Vec<Vec<u
3351
3351
fn read_ilst_data < T : Read > ( src : & mut BMFFBox < T > ) -> Result < Vec < u8 > > {
3352
3352
// Skip past the padding bytes
3353
3353
skip ( & mut src. content , src. head . offset ) ?;
3354
- let size = src. content . limit ( ) . try_into ( ) ? ;
3354
+ let size = src. content . limit ( ) ;
3355
3355
read_buf ( & mut src. content , size)
3356
3356
}
3357
3357
@@ -3362,13 +3362,13 @@ fn skip<T: Read>(src: &mut T, bytes: u64) -> Result<()> {
3362
3362
}
3363
3363
3364
3364
/// Read size bytes into a Vector or return error.
3365
- fn read_buf < T : ReadBytesExt > ( src : & mut T , size : usize ) -> Result < Vec < u8 > > {
3365
+ fn read_buf < T : Read > ( src : & mut T , size : u64 ) -> Result < Vec < u8 > > {
3366
3366
if size > BUF_SIZE_LIMIT {
3367
3367
return Err ( Error :: InvalidData ( "read_buf size exceeds BUF_SIZE_LIMIT" ) ) ;
3368
3368
}
3369
- if let Ok ( mut buf) = allocate_read_buf ( size) {
3369
+ if let Ok ( mut buf) = allocate_read_buf ( size. try_into ( ) ? ) {
3370
3370
let r = src. read ( & mut buf) ?;
3371
- if r != size {
3371
+ if r != size. try_into ( ) ? {
3372
3372
return Err ( Error :: InvalidData ( "failed buffer read" ) ) ;
3373
3373
}
3374
3374
return Ok ( buf) ;
0 commit comments