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

Re: [PATCH 3/3] commit-graph.c: handle corrupt/missing trees

From
Jeff King <peff@peff.net>
Date
Sep 6, 2019, 17:37 UTC
Message-ID
<20190906173707.GF23181@sigill.intra.peff.net>
In-Reply-To
<ad34871d-bdc4-5b52-eff4-da03c6be1004@gmail.com>
On Fri, Sep 06, 2019 at 12:51:56PM -0400, Derrick Stolee wrote:
Show 24 quoted lines
> > This one in theory benefits lots of other callsites, too, since it means
> > we'll actually return NULL instead of nonsense like "8". But grepping
> > around for calls to this function, I found literally zero of them
> > actually bother checking for a NULL result. So there are probably dozens
> > of similar segfaults waiting to happen in other code paths.
> > Discouraging.
> >
> > This is sort-of attributable to my 834876630b (get_commit_tree(): return
> > NULL for broken tree, 2019-04-09). Before then it was a BUG(). However,
> > that state was relatively short-lived. Before 7b8a21dba1 (commit-graph:
> > lazy-load trees for commits, 2018-04-06), we'd have similarly returned
> > NULL (and anyway, BUG() is clearly wrong since it's a data error).
> > 
> > None of which argues against your patches, but it's kind of sad that the
> > issue is present in so many code paths. I wonder if we could be handling
> > this in a more central way, but I don't see how short of dying.
> 
> This is due to the mechanical conversion from using commit->tree->oid to
> get_commit_tree_oid(commit). Those consumers were not checking if the
> tree pointer was NULL, either, but they probably assumed that the
> parse_commit() call would have failed earlier. Now that we are using this
> method (for performance reasons to avoid creating too many 'struct tree's)
> it makes sense to convert some of them to checking the return value more
> carefully.

Right, none of this is new at all. We have historically been very loose about assuming that things like commit->tree were valid. And they _usually_ are. Even if we're missing the object on disk, lookup_tree() is happy to assign it a struct (unless the object was already seen as another type!). I think turning that case into an error from parse_commit() would cover a lot of cases easily, without forcing each caller to check for NULL.

-Peff
Previous: Derrick StoleeNext: Junio C Hamano
Message 10 of 15 in “commit-graph: harden against various corruptions”
  1. 0/3 commit-graph: harden against various corruptionsTaylor Blau, Sep 5, 2019
  2. 1/3 t/t5318: introduce failing 'git commit-graph write' testsTaylor Blau, Sep 5, 2019
  3. Derrick StoleeSep 6, 2019
  4. 2/3 commit-graph.c: handle commit parsing errorsTaylor Blau, Sep 5, 2019
  5. 3/3 commit-graph.c: handle corrupt/missing treesTaylor Blau, Sep 5, 2019
  6. Jeff KingSep 6, 2019
  7. Taylor BlauSep 6, 2019
  8. Jeff KingSep 6, 2019
  9. Derrick StoleeSep 6, 2019
  10. Jeff KingSep 6, 2019
  11. Junio C HamanoSep 6, 2019
  12. Junio C HamanoSep 6, 2019
  13. Jeff KingSep 6, 2019
  14. Jeff KingSep 6, 2019
  15. Junio C HamanoSep 9, 2019

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.