@@ -952,7 +952,9 @@ int midx_verify(const char *pack_dir, const char *midx_id)
952
952
uint32_t i , cur_fanout_pos = 0 ;
953
953
struct midxed_git * m ;
954
954
const char * midx_head_path ;
955
- struct object_id cur_oid , prev_oid ;
955
+ struct object_id cur_oid , prev_oid , checksum ;
956
+ struct hashfile * f ;
957
+ int devnull , checksum_fail = 0 ;
956
958
957
959
if (midx_id ) {
958
960
size_t sz ;
@@ -970,6 +972,17 @@ int midx_verify(const char *pack_dir, const char *midx_id)
970
972
goto cleanup ;
971
973
}
972
974
975
+
976
+ devnull = open ("/dev/null" , O_WRONLY );
977
+ f = hashfd (devnull , NULL );
978
+ hashwrite (f , m -> data , m -> data_len - m -> hdr -> hash_len );
979
+ finalize_hashfile (f , checksum .hash , CSUM_CLOSE );
980
+ if (hashcmp (checksum .hash , m -> data + m -> data_len - m -> hdr -> hash_len )) {
981
+ midx_report (_ ("the midx file has incorrect checksum and is likely corrupt" ));
982
+ verify_midx_error = 0 ;
983
+ checksum_fail = 1 ;
984
+ }
985
+
973
986
if (m -> hdr -> hash_version != MIDX_OID_VERSION )
974
987
midx_report ("invalid hash version" );
975
988
if (m -> hdr -> hash_len != MIDX_OID_LEN )
@@ -987,8 +1000,6 @@ int midx_verify(const char *pack_dir, const char *midx_id)
987
1000
goto cleanup ;
988
1001
989
1002
for (i = 0 ; i < m -> num_packs ; i ++ ) {
990
- fprintf (stderr , "preparing %s\n" , m -> pack_names [i ]);
991
- fflush (stderr );
992
1003
if (prepare_midx_pack (m , i )) {
993
1004
midx_report ("failed to prepare pack %s" ,
994
1005
m -> pack_names [i ]);
@@ -1060,5 +1071,5 @@ int midx_verify(const char *pack_dir, const char *midx_id)
1060
1071
if (m )
1061
1072
close_midx (m );
1062
1073
free (m );
1063
- return verify_midx_error ;
1074
+ return verify_midx_error | checksum_fail ;
1064
1075
}
0 commit comments