# Re: \[PATCH\] apply: improve error messages when reading patch

- From: Junio C Hamano \<hidden\>
- Date: 2023-06-26 15:58:35 
- List: git
- Page: https://ratatoskr.run/git/2023/06/7971827
- Thread: https://ratatoskr.run/git/2023/06/7971827/t.md

```text
"Phillip Wood via GitGitGadget" [ref] writes:

> From: Phillip Wood <redacted>
>
> 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.
```
