Skip to content

Commit 84b889b

Browse files
committed
Merge branch 'pw/apply-too-large'
"git apply" punts when it is fed too large a patch input; the error message it gives when it happens has been clarified. * pw/apply-too-large: apply: improve error messages when reading patch
2 parents a9cc3b8 + 42612e1 commit 84b889b

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

apply.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,10 @@ static void say_patch_name(FILE *output, const char *fmt, struct patch *patch)
414414

415415
static int read_patch_file(struct strbuf *sb, int fd)
416416
{
417-
if (strbuf_read(sb, fd, 0) < 0 || sb->len >= MAX_APPLY_SIZE)
418-
return error_errno("git apply: failed to read");
419-
417+
if (strbuf_read(sb, fd, 0) < 0)
418+
return error_errno(_("failed to read patch"));
419+
else if (sb->len >= MAX_APPLY_SIZE)
420+
return error(_("patch too large"));
420421
/*
421422
* Make sure that we have some slop in the buffer
422423
* so that we can do speculative "memcmp" etc, and

t/t4141-apply-too-large.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ test_expect_success EXPENSIVE 'git apply rejects patches that are too large' '
1717
EOF
1818
test-tool genzeros
1919
} | test_copy_bytes $sz | test_must_fail git apply 2>err &&
20-
grep "git apply: failed to read" err
20+
grep "patch too large" err
2121
'
2222

2323
test_done

0 commit comments

Comments
 (0)