diff options
author | nulltoken <emeric.fermas@gmail.com> | 2013-08-13 15:26:14 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2013-08-15 22:15:53 +0400 |
commit | 7eb9ccfbffe2b309d91186f6850e41f997fa974d (patch) | |
tree | 34917d141e2a994f33b464e78559d8de0638e64b /LibGit2Sharp/OdbBackend.cs | |
parent | 3e29b4b2bc9dbae77b6a678bd96f3e50f5f42162 (diff) |
Allow handling of odd-sized short Shas in OdbBackend
Diffstat (limited to 'LibGit2Sharp/OdbBackend.cs')
-rw-r--r-- | LibGit2Sharp/OdbBackend.cs | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/LibGit2Sharp/OdbBackend.cs b/LibGit2Sharp/OdbBackend.cs index 9cfa4807..1fe11ec4 100644 --- a/LibGit2Sharp/OdbBackend.cs +++ b/LibGit2Sharp/OdbBackend.cs @@ -61,6 +61,7 @@ namespace LibGit2Sharp /// Requests that this backend read an object. The object ID may not be complete (may be a prefix). /// </summary> public abstract int ReadPrefix(byte[] shortOid, + int prefixLen, out byte[] oid, out Stream data, out ObjectType objectType); @@ -275,10 +276,14 @@ namespace LibGit2Sharp { // The length of short_oid is described in characters (40 per full ID) vs. bytes (20) // which is what we care about. - byte[] shortOidArray = new byte[(long)len >> 1]; - Array.Copy(short_oid.Id, shortOidArray, shortOidArray.Length); + var oidLen = (int)len; - int toReturn = odbBackend.ReadPrefix(shortOidArray, out oid, out dataStream, out objectType); + // Ensure we allocate enough space to cope with odd-sized prefix + int arraySize = (oidLen + 1) >> 1; + var shortOidArray = new byte[arraySize]; + Array.Copy(short_oid.Id, shortOidArray, arraySize); + + int toReturn = odbBackend.ReadPrefix(shortOidArray, oidLen, out oid, out dataStream, out objectType); if (0 == toReturn) { |