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

Integer-overflow in read-cache.c can cause buffer-overflow (bug requires a crafted/corrupted index)

From
Mike Hommey <mh@glandium.org>
Date
Jul 8, 2016, 11:43 UTC
Message-ID
<20160708114302.GA20350@glandium.org>
Hi,

I had a procastination episode today and wrote https://glandium.org/blog/?p=3659 . It started with me looking what git was doing with the size of the index when writing the index header, leading me to find a rather improbable integer overflow in https://github.com/git/git/blob/5c589a73de4394ad125a4effac227b3aec856fa1/read-cache.c#L1040 requiring hundreds of gigabytes of memory before happening.

But right after I finished the post and clicked "publish", I actually looked at the reading side and found another separate integer overflow that can lead to buffer overflow.

The possible integer overflow is here: https://github.com/git/git/blob/5c589a73de4394ad125a4effac227b3aec856fa1/read-cache.c#L1589

where alloc_nr is: #define alloc_nr(x) (((x)+16)*3/2)

So a crafter header with a number of entries above 1.something billion would overflow (cache_nr is an unsigned int), and istate->cache would be allocated with less than it should.

Then there can be a buffer overflow when reading the entries.

But this all require a crafted or corrupted index. If an attacker has been able to alter your index, you've already lost.

So I'd say the risk is rather low on the security scale.
Cheers,
Mike
Message 1 of 1 in “Integer-overflow in read-cache.c can cause buffer-overflow (bug requires a crafted/corrupted index)”
  1. Mike HommeyJul 8, 2016

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.