mirror of
				https://git.proxmox.com/git/libgit2
				synced 2025-11-04 14:08:17 +00:00 
			
		
		
		
	Protect sha1_entry_pos call with mutex
There is an occasional assertion failure in sha1_entry_pos from pack_entry_find_index when running threaded. Holding the mutex around the code that grabs the index_map data and processes it makes this assertion failure go away.
This commit is contained in:
		
							parent
							
								
									81b7dec4ee
								
							
						
					
					
						commit
						8c535f3f68
					
				
							
								
								
									
										22
									
								
								src/pack.c
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/pack.c
									
									
									
									
									
								
							@ -1050,24 +1050,24 @@ static int pack_entry_find_offset(
 | 
				
			|||||||
	const git_oid *short_oid,
 | 
						const git_oid *short_oid,
 | 
				
			||||||
	size_t len)
 | 
						size_t len)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	const uint32_t *level1_ofs = p->index_map.data;
 | 
						const uint32_t *level1_ofs;
 | 
				
			||||||
	const unsigned char *index = p->index_map.data;
 | 
						const unsigned char *index;
 | 
				
			||||||
	unsigned hi, lo, stride;
 | 
						unsigned hi, lo, stride;
 | 
				
			||||||
	int pos, found = 0;
 | 
						int pos, found = 0;
 | 
				
			||||||
	const unsigned char *current = 0;
 | 
						const unsigned char *current = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	*offset_out = 0;
 | 
						*offset_out = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (index == NULL) {
 | 
						if (!p->index_map.data && pack_index_open(p) < 0)
 | 
				
			||||||
		int error;
 | 
							return git_odb__error_notfound("failed to open packfile", NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if ((error = pack_index_open(p)) < 0)
 | 
						if (git_mutex_lock(&p->lock) < 0)
 | 
				
			||||||
			return error;
 | 
							return packfile_error("failed to get lock for finding entry offset");
 | 
				
			||||||
		assert(p->index_map.data);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		index = p->index_map.data;
 | 
						assert(p->index_map.data);
 | 
				
			||||||
		level1_ofs = p->index_map.data;
 | 
					
 | 
				
			||||||
	}
 | 
						index = p->index_map.data;
 | 
				
			||||||
 | 
						level1_ofs = p->index_map.data;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (p->index_version > 1) {
 | 
						if (p->index_version > 1) {
 | 
				
			||||||
		level1_ofs += 2;
 | 
							level1_ofs += 2;
 | 
				
			||||||
@ -1093,6 +1093,8 @@ static int pack_entry_find_offset(
 | 
				
			|||||||
	/* Use git.git lookup code */
 | 
						/* Use git.git lookup code */
 | 
				
			||||||
	pos = sha1_entry_pos(index, stride, 0, lo, hi, p->num_objects, short_oid->id);
 | 
						pos = sha1_entry_pos(index, stride, 0, lo, hi, p->num_objects, short_oid->id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						git_mutex_unlock(&p->lock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (pos >= 0) {
 | 
						if (pos >= 0) {
 | 
				
			||||||
		/* An object matching exactly the oid was found */
 | 
							/* An object matching exactly the oid was found */
 | 
				
			||||||
		found = 1;
 | 
							found = 1;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user