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

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/odb.c
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2013-09-08 00:39:05 +0400
committernulltoken <emeric.fermas@gmail.com>2013-09-08 01:00:20 +0400
commit031f3f8028835c935d1e75ebd136aaaefffea821 (patch)
treef1464b2553df04c9860bfb9404c41a74b4509c0f /src/odb.c
parentef6389ad504037e7a4311adbf14f1fa5a5aa4190 (diff)
odb: Error when streaming in too [few|many] bytes
Diffstat (limited to 'src/odb.c')
-rw-r--r--src/odb.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/odb.c b/src/odb.c
index dfb252178..2e6869547 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -888,17 +888,44 @@ int git_odb_open_wstream(
hash_header(ctx, size, type);
(*stream)->hash_ctx = ctx;
+ (*stream)->declared_size = size;
+ (*stream)->received_bytes = 0;
+
return error;
}
+static int git_odb_stream__invalid_length(
+ const git_odb_stream *stream,
+ const char *action)
+{
+ giterr_set(GITERR_ODB,
+ "Cannot %s - "
+ "Invalid length. %"PRIuZ" was expected. The "
+ "total size of the received chunks amounts to %"PRIuZ".",
+ action, stream->declared_size, stream->received_bytes);
+
+ return -1;
+}
+
int git_odb_stream_write(git_odb_stream *stream, const char *buffer, size_t len)
{
git_hash_update(stream->hash_ctx, buffer, len);
+
+ stream->received_bytes += len;
+
+ if (stream->received_bytes > stream->declared_size)
+ return git_odb_stream__invalid_length(stream,
+ "stream_write()");
+
return stream->write(stream, buffer, len);
}
int git_odb_stream_finalize_write(git_oid *out, git_odb_stream *stream)
{
+ if (stream->received_bytes != stream->declared_size)
+ return git_odb_stream__invalid_length(stream,
+ "stream_finalize_write()");
+
git_hash_final(out, stream->hash_ctx);
if (git_odb_exists(stream->backend->odb, out))