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

Re: [PATCH] Avoid infinite loop in malformed packfiles

From
OBOri Bernstein <ori@eigenstate.org>
Date
Aug 23, 2020, 20:41 UTC
Message-ID
<20200823134144.d57c80322f479eb554bab9d1@eigenstate.org>
In-Reply-To
<672843a1-b98c-7567-a078-a2dacd4b7074@web.de>
On Sun, 23 Aug 2020 08:26:14 +0200, René Scharfe <l.s.r@web.de> wrote:
Show 13 quoted lines
> Am 23.08.20 um 05:11 schrieb Ori Bernstein:
> > In packfile.c:1680, there's an infinite loop that tries to get
> > to the base of a packfile. With offset deltas, the offset needs
> > to be greater than 0, so it's always walking backwards, and the
> > search is guaranteed to terminate.
> >
> > With reference deltas, there's no check for a cycle in the
> > references, so a cyclic reference will cause git to loop
> > infinitely, growing the delta_stack infinitely, which will
> > cause it to consume all available memory as as a full CPU
> > core.
> 
> "as as"?  Perhaps "and"?
I think I meant 'As well as' -- will fix.
 
Show 32 quoted lines
> 
> b5c0cbd8083 (pack-objects: use bitfield for object_entry::depth,
> 2018-04-14) limited the delta depth for new packs to 4095, so 10000
> seems reasonable.  Users with unreasonable packs would need to repack
> them with an older version of Git, though.  Not sure if that would
> affect anyone in practice.
> 
> >  #define UNPACK_ENTRY_STACK_PREALLOC 64
> 
> Hmm, setting a hard limit may allow to allocate the whole stack on the,
> ehm, stack.  That would get rid of the hybrid stack/heap allocation and
> thus simplify the code a bit.  10000 entries with 24 bytes each would be
> quite big, though, but that might be OK without recursion.  (And not in
> this patch anyway, of course.)
> 
> >  struct unpack_entry_stack_ent {
> >  	off_t obj_offset;
> > @@ -1715,6 +1716,12 @@ void *unpack_entry(struct repository *r, struct packed_git *p, off_t obj_offset,
> >  			break;
> >  		}
> >
> > +		if (delta_stack_nr > UNPACK_ENTRY_STACK_LIMIT) {
> > +			error("overlong delta chain at offset %jd from %s",
> > +			      (uintmax_t)curpos, p->pack_name);
> > +			goto out;
> > +		}
> 
> Other error handlers in this loop set data to NULL.  That's actually
> unnecessary because it's NULL to begin with and the loop is exited after
> setting it to some other value.  So not doing it here is fine.  (And a
> separate cleanup patch could remove the dead stores in the other
> handlers.)

Is there anything you'd like me to do in this patch, other than fixing the typo?

-- 
    Ori Bernstein
Previous: René ScharfeNext: René Scharfe
Message 6 of 20 in “Avoid infinite loop in malformed packfiles”
  1. Avoid infinite loop in malformed packfilesOri Bernstein, Aug 23, 2020
  2. ori@eigenstate.orgAug 23, 2020
  3. Eric SunshineAug 23, 2020
  4. Avoid infinite loop in malformed packfilesOri Bernstein, Aug 23, 2020
  5. René ScharfeAug 23, 2020
  6. Ori BernsteinAug 23, 2020
  7. René ScharfeAug 24, 2020
  8. Jeff KingAug 24, 2020
  9. Junio C HamanoAug 24, 2020
  10. Jeff KingAug 24, 2020
  11. Junio C HamanoAug 24, 2020
  12. ori@eigenstate.orgAug 30, 2020
  13. René ScharfeAug 30, 2020
  14. Junio C HamanoAug 30, 2020
  15. Jeff KingAug 31, 2020
  16. Junio C HamanoAug 31, 2020
  17. Jeff KingAug 31, 2020
  18. ori@eigenstate.orgAug 31, 2020
  19. Junio C HamanoAug 24, 2020
  20. Junio C HamanoAug 24, 2020

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.