commit-graph: check order while reading fanout chunk
We read the fanout chunk, storing a pointer to it, but only confirm that the entries are monotonic in a final "lite" verification step. Let's move that into the actual OIDF chunk callback, so that we can report problems immediately (for all the reasons given in the previous "commit-graph: abort as soon as we see a bogus chunk" commit). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
		
				
					committed by
					
						
						Junio C Hamano
					
				
			
			
				
	
			
			
			
						parent
						
							d3b6f6c631
						
					
				
				
					commit
					06fb135f8e
				
			@ -277,8 +277,6 @@ struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
 | 
			
		||||
 | 
			
		||||
static int verify_commit_graph_lite(struct commit_graph *g)
 | 
			
		||||
{
 | 
			
		||||
	int i;
 | 
			
		||||
 | 
			
		||||
	/*
 | 
			
		||||
	 * Basic validation shared between parse_commit_graph()
 | 
			
		||||
	 * which'll be called every time the graph is used, and the
 | 
			
		||||
@ -291,6 +289,20 @@ static int verify_commit_graph_lite(struct commit_graph *g)
 | 
			
		||||
	 * over g->num_commits, or runs a checksum on the commit-graph
 | 
			
		||||
	 * itself.
 | 
			
		||||
	 */
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int graph_read_oid_fanout(const unsigned char *chunk_start,
 | 
			
		||||
				 size_t chunk_size, void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct commit_graph *g = data;
 | 
			
		||||
	int i;
 | 
			
		||||
 | 
			
		||||
	if (chunk_size != 256 * sizeof(uint32_t))
 | 
			
		||||
		return error("commit-graph oid fanout chunk is wrong size");
 | 
			
		||||
	g->chunk_oid_fanout = (const uint32_t *)chunk_start;
 | 
			
		||||
	g->num_commits = ntohl(g->chunk_oid_fanout[255]);
 | 
			
		||||
 | 
			
		||||
	for (i = 0; i < 255; i++) {
 | 
			
		||||
		uint32_t oid_fanout1 = ntohl(g->chunk_oid_fanout[i]);
 | 
			
		||||
		uint32_t oid_fanout2 = ntohl(g->chunk_oid_fanout[i + 1]);
 | 
			
		||||
@ -304,17 +316,6 @@ static int verify_commit_graph_lite(struct commit_graph *g)
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int graph_read_oid_fanout(const unsigned char *chunk_start,
 | 
			
		||||
				 size_t chunk_size, void *data)
 | 
			
		||||
{
 | 
			
		||||
	struct commit_graph *g = data;
 | 
			
		||||
	if (chunk_size != 256 * sizeof(uint32_t))
 | 
			
		||||
		return error("commit-graph oid fanout chunk is wrong size");
 | 
			
		||||
	g->chunk_oid_fanout = (const uint32_t *)chunk_start;
 | 
			
		||||
	g->num_commits = ntohl(g->chunk_oid_fanout[255]);
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int graph_read_oid_lookup(const unsigned char *chunk_start,
 | 
			
		||||
				 size_t chunk_size, void *data)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
@ -867,6 +867,7 @@ test_expect_success 'reader notices out-of-bounds fanout' '
 | 
			
		||||
	check_corrupt_chunk OIDF 0 $(printf "%02x000000" $(test_seq 0 254)) &&
 | 
			
		||||
	cat >expect.err <<-\EOF &&
 | 
			
		||||
	error: commit-graph fanout values out of order
 | 
			
		||||
	error: commit-graph required OID fanout chunk missing or corrupted
 | 
			
		||||
	EOF
 | 
			
		||||
	test_cmp expect.err err
 | 
			
		||||
'
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user