Skip to content

Commit e0973bc

Browse files
committed
odb: verify hashes in read_prefix_1
While the function reading an object from the complete OID already verifies OIDs, we do not yet do so for reading objects from a partial OID. Do so when strict OID verification is enabled.
1 parent 1410962 commit e0973bc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/odb.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,18 @@ static int read_prefix_1(git_odb_object **out, git_odb *db,
11461146
if (!found)
11471147
return GIT_ENOTFOUND;
11481148

1149+
if (git_odb__strict_hash_verification) {
1150+
git_oid hash;
1151+
1152+
if ((error = git_odb_hash(&hash, raw.data, raw.len, raw.type)) < 0)
1153+
goto out;
1154+
1155+
if (!git_oid_equal(&found_full_oid, &hash)) {
1156+
error = git_odb__error_mismatch(&found_full_oid, &hash);
1157+
goto out;
1158+
}
1159+
}
1160+
11491161
if ((object = odb_object__alloc(&found_full_oid, &raw)) == NULL)
11501162
goto out;
11511163

0 commit comments

Comments
 (0)