Message ID | pull.1552.git.1687772253869.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 42612e18d2e7c002054b677df791b848b62c1628 |
Headers | show |
Series | apply: improve error messages when reading patch | expand |
"Phillip Wood via GitGitGadget" <gitgitgadget@gmail.com> writes: > From: Phillip Wood <phillip.wood@dunelm.org.uk> > > Commit f1c0e3946e (apply: reject patches larger than ~1 GiB, 2022-10-25) > added a limit on the size of patch that apply will process to avoid > integer overflows. The implementation re-used the existing error message > for when we are unable to read the patch. This is unfortunate because (a) it > does not signal to the user that the patch is being rejected because it > is too large and (b) it uses error_errno() without setting errno. Good description of the issue, and ... > static int read_patch_file(struct strbuf *sb, int fd) > { > - if (strbuf_read(sb, fd, 0) < 0 || sb->len >= MAX_APPLY_SIZE) > - return error_errno("git apply: failed to read"); > - > + if (strbuf_read(sb, fd, 0) < 0) > + return error_errno(_("failed to read patch")); > + else if (sb->len >= MAX_APPLY_SIZE) > + return error(_("patch too large")); ... quite obvious improvement. Nice. Will queue. Thanks.
diff --git a/apply.c b/apply.c index 6212ab3a1b3..21c7f92ada8 100644 --- a/apply.c +++ b/apply.c @@ -410,9 +410,10 @@ static void say_patch_name(FILE *output, const char *fmt, struct patch *patch) static int read_patch_file(struct strbuf *sb, int fd) { - if (strbuf_read(sb, fd, 0) < 0 || sb->len >= MAX_APPLY_SIZE) - return error_errno("git apply: failed to read"); - + if (strbuf_read(sb, fd, 0) < 0) + return error_errno(_("failed to read patch")); + else if (sb->len >= MAX_APPLY_SIZE) + return error(_("patch too large")); /* * Make sure that we have some slop in the buffer * so that we can do speculative "memcmp" etc, and diff --git a/t/t4141-apply-too-large.sh b/t/t4141-apply-too-large.sh index 58742d4fc5d..20cc1209f62 100755 --- a/t/t4141-apply-too-large.sh +++ b/t/t4141-apply-too-large.sh @@ -17,7 +17,7 @@ test_expect_success EXPENSIVE 'git apply rejects patches that are too large' ' EOF test-tool genzeros } | test_copy_bytes $sz | test_must_fail git apply 2>err && - grep "git apply: failed to read" err + grep "patch too large" err ' test_done