@@ -18,7 +18,6 @@ use std::{
18
18
} ;
19
19
20
20
use byteorder:: { BigEndian , ReadBytesExt } ;
21
- use conv:: ValueFrom ;
22
21
use png_pong:: chunk:: InternationalText ;
23
22
use serde_bytes:: ByteBuf ;
24
23
@@ -339,10 +338,10 @@ impl CAIWriter for PngIO {
339
338
let mut iter = ps. into_iter ( ) ;
340
339
if let Some ( existing_cai_data) = iter. find ( |png_cp| png_cp. name == CAI_CHUNK ) {
341
340
// replace existing CAI data
342
- let cai_start = usize:: value_from ( existing_cai_data. start )
341
+ let cai_start = usize:: try_from ( existing_cai_data. start )
343
342
. map_err ( |_err| Error :: InvalidAsset ( "value out of range" . to_owned ( ) ) ) ?; // get beginning of chunk which starts 4 bytes before label
344
343
345
- let cai_end = usize:: value_from ( existing_cai_data. end ( ) )
344
+ let cai_end = usize:: try_from ( existing_cai_data. end ( ) )
346
345
. map_err ( |_err| Error :: InvalidAsset ( "value out of range" . to_owned ( ) ) ) ?;
347
346
348
347
png_buf. splice ( cai_start..cai_end, empty_buf. iter ( ) . cloned ( ) ) ;
@@ -356,7 +355,7 @@ impl CAIWriter for PngIO {
356
355
357
356
// add new cai data after the image header chunk
358
357
if let Some ( img_hdr) = iter. find ( |png_cp| png_cp. name == IMG_HDR ) {
359
- let img_hdr_end = usize:: value_from ( img_hdr. end ( ) )
358
+ let img_hdr_end = usize:: try_from ( img_hdr. end ( ) )
360
359
. map_err ( |_err| Error :: InvalidAsset ( "value out of range" . to_owned ( ) ) ) ?;
361
360
362
361
png_buf. splice ( img_hdr_end..img_hdr_end, cai_data. iter ( ) . cloned ( ) ) ;
@@ -450,10 +449,10 @@ impl CAIWriter for PngIO {
450
449
let mut iter = ps. into_iter ( ) ;
451
450
if let Some ( existing_cai) = iter. find ( |pcp| pcp. name == CAI_CHUNK ) {
452
451
// replace existing CAI
453
- let start = usize:: value_from ( existing_cai. start )
452
+ let start = usize:: try_from ( existing_cai. start )
454
453
. map_err ( |_err| Error :: InvalidAsset ( "value out of range" . to_string ( ) ) ) ?; // get beginning of chunk which starts 4 bytes before label
455
454
456
- let end = usize:: value_from ( existing_cai. end ( ) )
455
+ let end = usize:: try_from ( existing_cai. end ( ) )
457
456
. map_err ( |_err| Error :: InvalidAsset ( "value out of range" . to_string ( ) ) ) ?;
458
457
459
458
png_buf. splice ( start..end, empty_buf. iter ( ) . cloned ( ) ) ;
@@ -521,10 +520,10 @@ impl AssetIO for PngIO {
521
520
let mut iter = ps. into_iter ( ) ;
522
521
if let Some ( existing_cai) = iter. find ( |pcp| pcp. name == CAI_CHUNK ) {
523
522
// replace existing CAI
524
- let start = usize:: value_from ( existing_cai. start )
523
+ let start = usize:: try_from ( existing_cai. start )
525
524
. map_err ( |_err| Error :: InvalidAsset ( "value out of range" . to_string ( ) ) ) ?; // get beginning of chunk which starts 4 bytes before label
526
525
527
- let end = usize:: value_from ( existing_cai. end ( ) )
526
+ let end = usize:: try_from ( existing_cai. end ( ) )
528
527
. map_err ( |_err| Error :: InvalidAsset ( "value out of range" . to_string ( ) ) ) ?;
529
528
530
529
png_buf. splice ( start..end, empty_buf. iter ( ) . cloned ( ) ) ;
@@ -686,10 +685,10 @@ impl RemoteRefEmbed for PngIO {
686
685
. map_err ( Error :: IoError ) ?;
687
686
688
687
// replace existing XMP
689
- let xmp_start = usize:: value_from ( start)
688
+ let xmp_start = usize:: try_from ( start)
690
689
. map_err ( |_err| Error :: InvalidAsset ( "value out of range" . to_owned ( ) ) ) ?; // get beginning of chunk which starts 4 bytes before label
691
690
692
- let xmp_end = usize:: value_from ( start + xmp_len as u64 )
691
+ let xmp_end = usize:: try_from ( start + xmp_len as u64 )
693
692
. map_err ( |_err| Error :: InvalidAsset ( "value out of range" . to_owned ( ) ) ) ?;
694
693
695
694
png_buf. splice ( xmp_start..xmp_end, xmp_data. iter ( ) . cloned ( ) ) ;
0 commit comments