@@ -275,59 +275,27 @@ struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
275
275
return ret ;
276
276
}
277
277
278
- static int verify_commit_graph_lite (struct commit_graph * g )
278
+ static int graph_read_oid_fanout (const unsigned char * chunk_start ,
279
+ size_t chunk_size , void * data )
279
280
{
281
+ struct commit_graph * g = data ;
280
282
int i ;
281
283
282
- /*
283
- * Basic validation shared between parse_commit_graph()
284
- * which'll be called every time the graph is used, and the
285
- * much more expensive verify_commit_graph() used by
286
- * "commit-graph verify".
287
- *
288
- * There should only be very basic checks here to ensure that
289
- * we don't e.g. segfault in fill_commit_in_graph(), but
290
- * because this is a very hot codepath nothing that e.g. loops
291
- * over g->num_commits, or runs a checksum on the commit-graph
292
- * itself.
293
- */
294
- if (!g -> chunk_oid_fanout ) {
295
- error ("commit-graph is missing the OID Fanout chunk" );
296
- return 1 ;
297
- }
298
- if (!g -> chunk_oid_lookup ) {
299
- error ("commit-graph is missing the OID Lookup chunk" );
300
- return 1 ;
301
- }
302
- if (!g -> chunk_commit_data ) {
303
- error ("commit-graph is missing the Commit Data chunk" );
304
- return 1 ;
305
- }
284
+ if (chunk_size != 256 * sizeof (uint32_t ))
285
+ return error (_ ("commit-graph oid fanout chunk is wrong size" ));
286
+ g -> chunk_oid_fanout = (const uint32_t * )chunk_start ;
287
+ g -> num_commits = ntohl (g -> chunk_oid_fanout [255 ]);
306
288
307
289
for (i = 0 ; i < 255 ; i ++ ) {
308
290
uint32_t oid_fanout1 = ntohl (g -> chunk_oid_fanout [i ]);
309
291
uint32_t oid_fanout2 = ntohl (g -> chunk_oid_fanout [i + 1 ]);
310
292
311
293
if (oid_fanout1 > oid_fanout2 ) {
312
- error ("commit-graph fanout values out of order" );
294
+ error (_ ( "commit-graph fanout values out of order" ) );
313
295
return 1 ;
314
296
}
315
297
}
316
- if (ntohl (g -> chunk_oid_fanout [255 ]) != g -> num_commits ) {
317
- error ("commit-graph oid table and fanout disagree on size" );
318
- return 1 ;
319
- }
320
-
321
- return 0 ;
322
- }
323
298
324
- static int graph_read_oid_fanout (const unsigned char * chunk_start ,
325
- size_t chunk_size , void * data )
326
- {
327
- struct commit_graph * g = data ;
328
- if (chunk_size != 256 * sizeof (uint32_t ))
329
- return error ("commit-graph oid fanout chunk is wrong size" );
330
- g -> chunk_oid_fanout = (const uint32_t * )chunk_start ;
331
299
return 0 ;
332
300
}
333
301
@@ -336,16 +304,17 @@ static int graph_read_oid_lookup(const unsigned char *chunk_start,
336
304
{
337
305
struct commit_graph * g = data ;
338
306
g -> chunk_oid_lookup = chunk_start ;
339
- g -> num_commits = chunk_size / g -> hash_len ;
307
+ if (chunk_size / g -> hash_len != g -> num_commits )
308
+ return error (_ ("commit-graph OID lookup chunk is the wrong size" ));
340
309
return 0 ;
341
310
}
342
311
343
312
static int graph_read_commit_data (const unsigned char * chunk_start ,
344
313
size_t chunk_size , void * data )
345
314
{
346
315
struct commit_graph * g = data ;
347
- if (chunk_size != g -> num_commits * GRAPH_DATA_WIDTH )
348
- return error ("commit-graph commit data chunk is wrong size" );
316
+ if (chunk_size / GRAPH_DATA_WIDTH != g -> num_commits )
317
+ return error (_ ( "commit-graph commit data chunk is wrong size" ) );
349
318
g -> chunk_commit_data = chunk_start ;
350
319
return 0 ;
351
320
}
@@ -354,8 +323,8 @@ static int graph_read_generation_data(const unsigned char *chunk_start,
354
323
size_t chunk_size , void * data )
355
324
{
356
325
struct commit_graph * g = data ;
357
- if (chunk_size != g -> num_commits * sizeof ( uint32_t ) )
358
- return error ("commit-graph generations chunk is wrong size" );
326
+ if (chunk_size / sizeof ( uint32_t ) != g -> num_commits )
327
+ return error (_ ( "commit-graph generations chunk is wrong size" ) );
359
328
g -> chunk_generation_data = chunk_start ;
360
329
return 0 ;
361
330
}
@@ -364,8 +333,8 @@ static int graph_read_bloom_index(const unsigned char *chunk_start,
364
333
size_t chunk_size , void * data )
365
334
{
366
335
struct commit_graph * g = data ;
367
- if (chunk_size != g -> num_commits * 4 ) {
368
- warning ("commit-graph changed-path index chunk is too small" );
336
+ if (chunk_size / 4 != g -> num_commits ) {
337
+ warning (_ ( "commit-graph changed-path index chunk is too small" ) );
369
338
return -1 ;
370
339
}
371
340
g -> chunk_bloom_indexes = chunk_start ;
@@ -379,8 +348,8 @@ static int graph_read_bloom_data(const unsigned char *chunk_start,
379
348
uint32_t hash_version ;
380
349
381
350
if (chunk_size < BLOOMDATA_CHUNK_HEADER_SIZE ) {
382
- warning ("ignoring too-small changed-path chunk"
383
- " (%" PRIuMAX " < %" PRIuMAX ") in commit-graph file" ,
351
+ warning (_ ( "ignoring too-small changed-path chunk"
352
+ " (%" PRIuMAX " < %" PRIuMAX ") in commit-graph file" ) ,
384
353
(uintmax_t )chunk_size ,
385
354
(uintmax_t )BLOOMDATA_CHUNK_HEADER_SIZE );
386
355
return -1 ;
@@ -462,9 +431,19 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
462
431
GRAPH_HEADER_SIZE , graph -> num_chunks , 1 ))
463
432
goto free_and_return ;
464
433
465
- read_chunk (cf , GRAPH_CHUNKID_OIDFANOUT , graph_read_oid_fanout , graph );
466
- read_chunk (cf , GRAPH_CHUNKID_OIDLOOKUP , graph_read_oid_lookup , graph );
467
- read_chunk (cf , GRAPH_CHUNKID_DATA , graph_read_commit_data , graph );
434
+ if (read_chunk (cf , GRAPH_CHUNKID_OIDFANOUT , graph_read_oid_fanout , graph )) {
435
+ error (_ ("commit-graph required OID fanout chunk missing or corrupted" ));
436
+ goto free_and_return ;
437
+ }
438
+ if (read_chunk (cf , GRAPH_CHUNKID_OIDLOOKUP , graph_read_oid_lookup , graph )) {
439
+ error (_ ("commit-graph required OID lookup chunk missing or corrupted" ));
440
+ goto free_and_return ;
441
+ }
442
+ if (read_chunk (cf , GRAPH_CHUNKID_DATA , graph_read_commit_data , graph )) {
443
+ error (_ ("commit-graph required commit data chunk missing or corrupted" ));
444
+ goto free_and_return ;
445
+ }
446
+
468
447
pair_chunk (cf , GRAPH_CHUNKID_EXTRAEDGES , & graph -> chunk_extra_edges ,
469
448
& graph -> chunk_extra_edges_size );
470
449
pair_chunk (cf , GRAPH_CHUNKID_BASE , & graph -> chunk_base_graphs ,
@@ -499,9 +478,6 @@ struct commit_graph *parse_commit_graph(struct repo_settings *s,
499
478
500
479
oidread (& graph -> oid , graph -> data + graph -> data_len - graph -> hash_len );
501
480
502
- if (verify_commit_graph_lite (graph ))
503
- goto free_and_return ;
504
-
505
481
free_chunkfile (cf );
506
482
return graph ;
507
483
@@ -629,7 +605,7 @@ int open_commit_graph_chain(const char *chain_file,
629
605
/* treat empty files the same as missing */
630
606
errno = ENOENT ;
631
607
} else {
632
- warning ("commit-graph chain file too small" );
608
+ warning (_ ( "commit-graph chain file too small" ) );
633
609
errno = EINVAL ;
634
610
}
635
611
return 0 ;
@@ -970,7 +946,7 @@ static int fill_commit_in_graph(struct repository *r,
970
946
parent_data_pos = edge_value & GRAPH_EDGE_LAST_MASK ;
971
947
do {
972
948
if (g -> chunk_extra_edges_size / sizeof (uint32_t ) <= parent_data_pos ) {
973
- error ("commit-graph extra-edges pointer out of bounds" );
949
+ error (_ ( "commit-graph extra-edges pointer out of bounds" ) );
974
950
free_commit_list (item -> parents );
975
951
item -> parents = NULL ;
976
952
item -> object .parsed = 0 ;
@@ -2690,10 +2666,6 @@ static int verify_one_commit_graph(struct repository *r,
2690
2666
struct commit * seen_gen_zero = NULL ;
2691
2667
struct commit * seen_gen_non_zero = NULL ;
2692
2668
2693
- verify_commit_graph_error = verify_commit_graph_lite (g );
2694
- if (verify_commit_graph_error )
2695
- return verify_commit_graph_error ;
2696
-
2697
2669
if (!commit_graph_checksum_valid (g )) {
2698
2670
graph_report (_ ("the commit-graph file has incorrect checksum and is likely corrupt" ));
2699
2671
verify_commit_graph_error = VERIFY_COMMIT_GRAPH_ERROR_HASH ;
0 commit comments