Commit 3d9ef2dc by Vicent Marti

Revert "object: correct the expected ID size in prefix lookup"

This reverts commit 969d4b70.

This was a fluke from Coverity. The length to all the APIs in the
library is supposed to be passed in as nibbles, not bytes. Passing it as
bytes would prevent us from parsing uneven-sized SHA1 strings.

Also, the rest of the library was still using nibbles (including
revparse and the odb_prefix APIs), so this change was seriously breaking
things in unexpected ways. ^^
parent 14888070
...@@ -129,10 +129,10 @@ int git_object_lookup_prefix( ...@@ -129,10 +129,10 @@ int git_object_lookup_prefix(
if (error < 0) if (error < 0)
return error; return error;
if (len > GIT_OID_RAWSZ) if (len > GIT_OID_HEXSZ)
len = GIT_OID_RAWSZ; len = GIT_OID_HEXSZ;
if (len == GIT_OID_RAWSZ) { if (len == GIT_OID_HEXSZ) {
git_cached_obj *cached = NULL; git_cached_obj *cached = NULL;
/* We want to match the full id : we can first look up in the cache, /* We want to match the full id : we can first look up in the cache,
...@@ -172,9 +172,9 @@ int git_object_lookup_prefix( ...@@ -172,9 +172,9 @@ int git_object_lookup_prefix(
memcpy(short_oid.id, id->id, (len + 1) / 2); memcpy(short_oid.id, id->id, (len + 1) / 2);
if (len % 2) if (len % 2)
short_oid.id[len / 2] &= 0xF0; short_oid.id[len / 2] &= 0xF0;
memset(short_oid.id + (len + 1) / 2, 0, (GIT_OID_RAWSZ - len) / 2); memset(short_oid.id + (len + 1) / 2, 0, (GIT_OID_HEXSZ - len) / 2);
/* If len < GIT_OID_RAWSZ (a strict short oid was given), we have /* If len < GIT_OID_HEXSZ (a strict short oid was given), we have
* 2 options : * 2 options :
* - We always search in the cache first. If we find that short oid is * - We always search in the cache first. If we find that short oid is
* ambiguous, we can stop. But in all the other cases, we must then * ambiguous, we can stop. But in all the other cases, we must then
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment