@@ -195,7 +195,8 @@ impl UploadState {
195195 usize :: try_from( max_index_count)
196196 . err_tip( || "Could not convert max_index_count to usize" ) ?
197197 ] ,
198- index_count : max_index_count as u32 ,
198+ index_count : u32:: try_from ( max_index_count)
199+ . err_tip ( || "Could not convert max_index_count to u32" ) ?,
199200 uncompressed_data_size : 0 , // Updated later.
200201 config : header. config ,
201202 version : CURRENT_STREAM_FORMAT_VERSION ,
@@ -361,14 +362,18 @@ impl StoreDriver for CompressionStore {
361362 }
362363
363364 // Now fill the size in our slice.
364- LittleEndian :: write_u32 ( & mut compressed_data_buf[ 1 ..5 ] , compressed_data_sz as u32 ) ;
365+ LittleEndian :: write_u32 (
366+ & mut compressed_data_buf[ 1 ..5 ] ,
367+ u32:: try_from ( compressed_data_sz) . unwrap_or ( u32:: MAX ) ,
368+ ) ;
365369
366370 // Now send our chunk.
367371 tx. send ( compressed_data_buf. freeze ( ) )
368372 . await
369373 . err_tip ( || "Failed to write chunk to inner store in compression store" ) ?;
370374
371- index. position_from_prev_index = compressed_data_sz as u32 ;
375+ index. position_from_prev_index =
376+ u32:: try_from ( compressed_data_sz) . unwrap_or ( u32:: MAX ) ;
372377
373378 index_count += 1 ;
374379 }
@@ -384,7 +389,8 @@ impl StoreDriver for CompressionStore {
384389 . footer
385390 . indexes
386391 . resize ( index_count as usize , SliceIndex :: default ( ) ) ;
387- output_state. footer . index_count = output_state. footer . indexes . len ( ) as u32 ;
392+ output_state. footer . index_count =
393+ u32:: try_from ( output_state. footer . indexes . len ( ) ) . unwrap_or ( u32:: MAX ) ;
388394 output_state. footer . uncompressed_data_size = received_amt;
389395 {
390396 // Write Footer.
@@ -395,7 +401,7 @@ impl StoreDriver for CompressionStore {
395401
396402 let mut footer = BytesMut :: with_capacity ( 1 + 4 + serialized_footer. len ( ) ) ;
397403 footer. put_u8 ( FOOTER_FRAME_TYPE ) ;
398- footer. put_u32_le ( serialized_footer. len ( ) as u32 ) ;
404+ footer. put_u32_le ( u32 :: try_from ( serialized_footer. len ( ) ) . unwrap_or ( u32:: MAX ) ) ;
399405 footer. extend_from_slice ( & serialized_footer) ;
400406
401407 tx. send ( footer. freeze ( ) )
@@ -453,7 +459,7 @@ impl StoreDriver for CompressionStore {
453459 } ;
454460 let header_size = serialized_size ( & EMPTY_HEADER , self . bincode_config ) ?;
455461 let chunk = rx
456- . consume ( Some ( header_size as usize ) )
462+ . consume ( Some ( usize :: try_from ( header_size) . unwrap_or ( usize:: MAX ) ) )
457463 . await
458464 . err_tip ( || "Failed to read header in get_part compression store" ) ?;
459465 error_if ! (
@@ -536,9 +542,13 @@ impl StoreDriver for CompressionStore {
536542 let new_uncompressed_data_sz =
537543 uncompressed_data_sz + uncompressed_chunk_sz as u64 ;
538544 if new_uncompressed_data_sz >= offset && remaining_bytes_to_send > 0 {
539- let start_pos = offset. saturating_sub ( uncompressed_data_sz) as usize ;
545+ let start_pos =
546+ usize:: try_from ( offset. saturating_sub ( uncompressed_data_sz) )
547+ . unwrap_or ( usize:: MAX ) ;
540548 let end_pos = cmp:: min (
541- start_pos + remaining_bytes_to_send as usize ,
549+ start_pos. saturating_add (
550+ usize:: try_from ( remaining_bytes_to_send) . unwrap_or ( usize:: MAX ) ,
551+ ) ,
542552 uncompressed_chunk_sz,
543553 ) ;
544554 if end_pos != start_pos {
0 commit comments