Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-05-29 15:46:59 +0400
committernulltoken <emeric.fermas@gmail.com>2014-05-30 20:37:07 +0400
commit9b0b947874dbbd58c70972683f3dc4a2995f3d50 (patch)
tree7868edf95a1b4b9a9bae8a7e633509cc65abb0b0 /LibGit2Sharp
parent6a7a166be2923352774a55f376c31367b1409ef3 (diff)
ObjectDatabase: we should fail when asked to read too much
ObjectDatabase.CreateBlob() accepts a number of bytes to read. It currently however treats this as a max, rather than a hard size, which seems ripe for introducing bugs. Assert that we should throw when asked to read too much from a Stream.
Diffstat (limited to 'LibGit2Sharp')
-rw-r--r--LibGit2Sharp/Core/Proxy.cs6
-rw-r--r--LibGit2Sharp/ObjectDatabase.cs12
2 files changed, 18 insertions, 0 deletions
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index f3fc97dd..e09a7fa0 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -69,6 +69,12 @@ namespace LibGit2Sharp.Core
{
var oid = new GitOid();
int res = NativeMethods.git_blob_create_fromchunks(ref oid, repo, hintpath, fileCallback, IntPtr.Zero);
+
+ if (res == (int)GitErrorCode.User)
+ {
+ throw new EndOfStreamException("The stream ended unexpectedly");
+ }
+
Ensure.ZeroResult(res);
return oid;
diff --git a/LibGit2Sharp/ObjectDatabase.cs b/LibGit2Sharp/ObjectDatabase.cs
index f40ec4e8..b200649e 100644
--- a/LibGit2Sharp/ObjectDatabase.cs
+++ b/LibGit2Sharp/ObjectDatabase.cs
@@ -138,7 +138,19 @@ namespace LibGit2Sharp
}
}
+ if (bytesToRead == 0)
+ {
+ return 0;
+ }
+
int numberOfReadBytes = stream.Read(local, 0, bytesToRead);
+
+ if (numberOfBytesToConsume.HasValue
+ && numberOfReadBytes == 0)
+ {
+ return (int)GitErrorCode.User;
+ }
+
totalNumberOfReadBytes += numberOfReadBytes;
Marshal.Copy(local, 0, content, numberOfReadBytes);