git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] tree-walk: disallow overflowing modes

From
Jeff King <peff@peff.net>
Date
Jan 22, 2023, 22:02 UTC
Message-ID
<Y82yXskkgH00vaGy@coredump.intra.peff.net>
In-Reply-To
<044bdc8f-fdc9-dfd2-6cbb-941513467524@web.de>
On Sun, Jan 22, 2023 at 11:03:38AM +0100, René Scharfe wrote:
Show 14 quoted lines
> Am 22.01.23 um 08:50 schrieb Jeff King:
> > On Sat, Jan 21, 2023 at 10:36:09AM +0100, René Scharfe wrote:
> >
> >> When parsing tree entries, reject mode values that don't fit into an
> >> unsigned int.
> >
> > Seems reasonable. I don't think you can cause any interesting mischief
> > here, but it's cheap to check, and finding data problems earlier rather
> > than later is always good.
> >
> > Should it be s/unsigned int/uint16_t/, though?
> 
> "mode" is declared as unsigned int, and I was more concerned with
> overflowing that.

Doh, I just did "vim -t get_mode" and ended up in the near-identical version in fast-import.c, which uses uint16_t. Maybe it would want the same treatment. ;)

> We could be more strict and reject everything that oversteps
> S_IFMT|ALLPERMS, but the latter is not defined everywhere.  But
> permission bits are well-known, so the magic number 07777 should be
> recognizable enough.  Like this?

It feels like this level of check should be happening in the fsck caller. In particular, it's nice for this parsing layer to err on the forgiving side, because the way you get out of these situations often involves something like "git ls-tree | git mktree".

So in that sense, even pushing the overflow detection into the fsck would be nice, but of course it's hard to do, since we have no way to represent the overflowed value. I guess we could have a "be more careful" flag that the fsck code would pass, but I'm not sure it's worth the added complexity.

-Peff
Previous: Junio C HamanoNext: Ævar Arnfjörð Bjarmason
Message 5 of 9 in “tree-walk: disallow overflowing modes”
  1. tree-walk: disallow overflowing modesRené Scharfe, Jan 21, 2023
  2. Jeff KingJan 22, 2023
  3. René ScharfeJan 22, 2023
  4. Junio C HamanoJan 22, 2023
  5. Jeff KingJan 22, 2023
  6. Ævar Arnfjörð BjarmasonJan 23, 2023
  7. René ScharfeJan 24, 2023
  8. Junio C HamanoJan 24, 2023
  9. Jeff KingJan 26, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.