From: Taylor Blau <me@ttaylorr.com> To: Jeff King <peff@peff.net> Cc: Junio C Hamano <gitster@pobox.com>, git@vger.kernel.org Subject: Re: [PATCH 6/6] config: reject parsing of files over INT_MAX Date: Sun, 12 Apr 2020 18:47:24 -0600 [thread overview] Message-ID: <20200413004724.GB55122@syl.local> (raw) In-Reply-To: <20200410221549.GA2078378@coredump.intra.peff.net> On Fri, Apr 10, 2020 at 06:15:49PM -0400, Jeff King wrote: > On Fri, Apr 10, 2020 at 03:04:31PM -0700, Junio C Hamano wrote: > > > Jeff King <peff@peff.net> writes: > > > > > So given the fact that these are insane cases which we have no need to > > > support, the weird behavior from feeding the results to printf even if > > > the code is careful, and the possibility of uncareful code introducing > > > its own integer truncation issues, let's just declare INT_MAX as a limit > > > for parsing config files. > > > > Makes sense. > > > > > + if (c != EOF && ++cf->total_len > INT_MAX) { > > > > Would this work correctly if size_t is uint? Sure, as int-max would > > fit within it. And of course if size_t is wider than uint, there is > > no problem in this comparison. > > Good question, but yeah, I think it's right. > > Another method would be to do: > > if (cf->total_len >= INT_MAX) > > _before_ reading any character. We'd have to remember to increment > total_len then (I suppose we could do it preemptively; as long as people > don't try to read EOF from us over and over again it would never move > again). > > I also considered making the limit much lower than INT_MAX because > really, who needs even a 1GB config file? :) ;). Making it lower than INT_MAX moves us into the territory of deciding what is an "appropriately" sized config file, which I'd rather not do. At least we can blame INT_MAX if someone has a too-large config file. > -Peff Thanks, Taylor
next prev parent reply other threads:[~2020-04-13 0:47 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-04-10 19:42 [PATCH 0/6] better handling of gigantic config files Jeff King 2020-04-10 19:43 ` [PATCH 1/6] remote: drop auto-strlen behavior of make_branch() and make_rewrite() Jeff King 2020-04-10 21:44 ` Junio C Hamano 2020-04-10 19:44 ` [PATCH 2/6] parse_config_key(): return subsection len as size_t Jeff King 2020-04-10 19:44 ` [PATCH 3/6] config: drop useless length variable in write_pair() Jeff King 2020-04-10 21:51 ` Junio C Hamano 2020-04-10 19:46 ` [PATCH 4/6] git_config_parse_key(): return baselen as size_t Jeff King 2020-04-10 19:47 ` [PATCH 5/6] config: use size_t to store parsed variable baselen Jeff King 2020-04-10 19:50 ` [PATCH 6/6] config: reject parsing of files over INT_MAX Jeff King 2020-04-10 22:04 ` Junio C Hamano 2020-04-10 22:15 ` Jeff King 2020-04-13 0:47 ` Taylor Blau [this message] 2020-04-13 22:14 ` Junio C Hamano 2020-04-13 0:49 ` [PATCH 0/6] better handling of gigantic config files Taylor Blau 2020-04-13 17:20 ` Jeff King 2020-04-13 17:23 ` Taylor Blau
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: http://vger.kernel.org/majordomo-info.html * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200413004724.GB55122@syl.local \ --to=me@ttaylorr.com \ --cc=git@vger.kernel.org \ --cc=gitster@pobox.com \ --cc=peff@peff.net \ --subject='Re: [PATCH 6/6] config: reject parsing of files over INT_MAX' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Code repositories for project(s) associated with this inbox: https://80x24.org/mirrors/git.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).