@@ -115,7 +115,7 @@ impl TryFrom<&Path> for File {
115
115
let base_graph_count = data[ ofs] ;
116
116
ofs += 1 ;
117
117
118
- let chunk_lookup_end = ofs + ( ( chunk_count as usize + 1 ) * CHUNK_LOOKUP_SIZE ) ;
118
+ let chunk_lookup_end = ofs + ( ( usize:: from ( chunk_count ) + 1 ) * CHUNK_LOOKUP_SIZE ) ;
119
119
if chunk_lookup_end > data_size {
120
120
return Err ( Error :: Corrupt ( format ! (
121
121
"Commit-graph file is too small to hold {} chunks" ,
@@ -179,8 +179,10 @@ impl TryFrom<&Path> for File {
179
179
msg : format ! ( "chunk size {} is not a multiple of {}" , chunk_size, SHA1_SIZE ) ,
180
180
} ) ;
181
181
}
182
- let chunk_base_graph_count = ( chunk_size / SHA1_SIZE ) as u32 ;
183
- if chunk_base_graph_count != base_graph_count as u32 {
182
+ let chunk_base_graph_count: u32 = ( chunk_size / SHA1_SIZE )
183
+ . try_into ( )
184
+ . expect ( "base graph count to fit in 32-bits" ) ;
185
+ if chunk_base_graph_count != u32:: from ( base_graph_count) {
184
186
return Err ( Error :: BaseGraphMismatch {
185
187
from_chunk : chunk_base_graph_count,
186
188
from_header : base_graph_count,
@@ -202,7 +204,9 @@ impl TryFrom<&Path> for File {
202
204
} ) ;
203
205
}
204
206
commit_data_offset = Some ( chunk_offset) ;
205
- commit_data_count = ( chunk_size / COMMIT_DATA_ENTRY_SIZE ) as u32 ;
207
+ commit_data_count = ( chunk_size / COMMIT_DATA_ENTRY_SIZE )
208
+ . try_into ( )
209
+ . expect ( "number of commits in CDAT chunk to fit in 32 bits" ) ;
206
210
}
207
211
EXTENDED_EDGES_LIST_CHUNK_ID => {
208
212
if extra_edges_list_range. is_some ( ) {
@@ -241,7 +245,9 @@ impl TryFrom<&Path> for File {
241
245
} ) ;
242
246
}
243
247
oid_lookup_offset = Some ( chunk_offset) ;
244
- oid_lookup_count = ( chunk_size / OID_LOOKUP_ENTRY_SIZE ) as u32 ;
248
+ oid_lookup_count = ( chunk_size / OID_LOOKUP_ENTRY_SIZE )
249
+ . try_into ( )
250
+ . expect ( "number of commits in OIDL chunk to fit in 32 bits" ) ;
245
251
// TODO(ST): Figure out how to handle this. Don't know what to do with the commented code.
246
252
// git allows extra garbage in the extra edges list chunk?
247
253
// if oid_lookup_count > 0 {
0 commit comments