Re: [PATCH v5 2/5] setup: sanity check file size in read_gitfile_gently
- From
Jeff King <peff@peff.net>
- Date
- Apr 28, 2015, 06:02 UTC
- Message-ID
- <20150428060222.GK24580@peff.net>
- In-Reply-To
- <1430030985-14499-3-git-send-email-erik.elfstrom@gmail.com>
On Sun, Apr 26, 2015 at 08:49:42AM +0200, Erik Elfström wrote:
Show 12 quoted lines
> read_gitfile_gently will allocate a buffer to fit the entire file that
> should be read. Add a sanity check of the file size before opening to
> avoid allocating a potentially huge amount of memory if we come across
> a large file that someone happened to name ".git". The limit is set to
> a sufficiently unreasonable size that should never be exceeded by a
> genuine .git file.
>
> [...]
> + if (st.st_size > PATH_MAX * 4) {
> + error_code = READ_GITFILE_ERR_TOO_LARGE;
> + goto cleanup_return;
> + }My understanding is that PATH_MAX is set absurdly low on Windows systems (and doesn't actually represent the real limit of a path!). Since the value is picked arbitrarily anyway, could use something more independent (like 100K or something, which is large enough to be beyond absurd and small enough that a malloc isn't a big deal)?
-Peff