summaryrefslogtreecommitdiff
path: root/builtin/cat-file.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-11-13 13:37:17 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-11-13 13:37:17 (GMT)
commit879a8d4bf2412303ec940d69165b0937c11a2851 (patch)
treef610f532a4da757bc9b5480cce825e2e937bbb37 /builtin/cat-file.c
parentfd7761a1cd1d8ab5cb311b6e7f91e56496e95b84 (diff)
parent18ad13e5b2ee18c3f57bf41add3efa95980e72c1 (diff)
downloadgit-879a8d4bf2412303ec940d69165b0937c11a2851.zip
git-879a8d4bf2412303ec940d69165b0937c11a2851.tar.gz
git-879a8d4bf2412303ec940d69165b0937c11a2851.tar.bz2
Merge branch 'jk/detect-truncated-zlib-input'
A regression in Git 2.12 era made "git fsck" fall into an infinite loop while processing truncated loose objects. * jk/detect-truncated-zlib-input: cat-file: handle streaming failures consistently check_stream_sha1(): handle input underflow t1450: check large blob in trailing-garbage test
Diffstat (limited to 'builtin/cat-file.c')
-rw-r--r--builtin/cat-file.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 8d97c84..0d403eb 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -50,6 +50,13 @@ static int filter_object(const char *path, unsigned mode,
return 0;
}
+static int stream_blob(const struct object_id *oid)
+{
+ if (stream_blob_to_fd(1, oid, NULL, 0))
+ die("unable to stream %s to stdout", oid_to_hex(oid));
+ return 0;
+}
+
static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
int unknown_type)
{
@@ -132,7 +139,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
}
if (type == OBJ_BLOB)
- return stream_blob_to_fd(1, &oid, NULL, 0);
+ return stream_blob(&oid);
buf = read_object_file(&oid, &type, &size);
if (!buf)
die("Cannot read object %s", obj_name);
@@ -155,7 +162,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
oidcpy(&blob_oid, &oid);
if (oid_object_info(the_repository, &blob_oid, NULL) == OBJ_BLOB)
- return stream_blob_to_fd(1, &blob_oid, NULL, 0);
+ return stream_blob(&blob_oid);
/*
* we attempted to dereference a tag to a blob
* and failed; there may be new dereference
@@ -319,8 +326,9 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d
BUG("invalid cmdmode: %c", opt->cmdmode);
batch_write(opt, contents, size);
free(contents);
- } else if (stream_blob_to_fd(1, oid, NULL, 0) < 0)
- die("unable to stream %s to stdout", oid_to_hex(oid));
+ } else {
+ stream_blob(oid);
+ }
}
else {
enum object_type type;