From c6cac733c147ff800f78e7dff81f90d93369ea68 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Sun, 20 Jan 2019 22:40:38 +0000 Subject: blob: validate that blob sizes fit in a size_t Our blob size is a `git_off_t`, which is a signed 64 bit int. This may be erroneously negative or larger than `SIZE_MAX`. Ensure that the blob size fits into a `size_t` before casting. --- src/odb.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/odb.c') diff --git a/src/odb.c b/src/odb.c index b74d42f3b..498652c79 100644 --- a/src/odb.c +++ b/src/odb.c @@ -15,6 +15,7 @@ #include "delta.h" #include "filter.h" #include "repository.h" +#include "blob.h" #include "git2/odb_backend.h" #include "git2/oid.h" @@ -387,18 +388,17 @@ static void fake_wstream__free(git_odb_stream *_stream) static int init_fake_wstream(git_odb_stream **stream_p, git_odb_backend *backend, git_off_t size, git_object_t type) { fake_wstream *stream; + size_t blobsize; - if (!git__is_ssizet(size)) { - git_error_set(GIT_ERROR_ODB, "object size too large to keep in memory"); - return -1; - } + GIT_ERROR_CHECK_BLOBSIZE(size); + blobsize = (size_t)size; stream = git__calloc(1, sizeof(fake_wstream)); GIT_ERROR_CHECK_ALLOC(stream); - stream->size = size; + stream->size = blobsize; stream->type = type; - stream->buffer = git__malloc(size); + stream->buffer = git__malloc(blobsize); if (stream->buffer == NULL) { git__free(stream); return -1; -- cgit v1.2.1