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

[BUG] Integer overflow when supplying large context value to diff --unified

From
BMBranko Majic <branko@majic.rs>
Date
Feb 9, 2018, 15:01 UTC
Message-ID
<20180209160147.3f54a362@majic.rs>
Hello,
Git versions tested: 2.13.6, 2.1.4

When passing-in a large context value for the --unified option for git-diff, Git will produce an invalid-looking range information for hunks.

For example, if running 'git diff --unified=10 HEAD^', the output will include (this is just a run against my local git repo):

@@ -42,23 +42,23 @@ master_doc = 'index'

Note the numbers for denoting begin/end line etc "look fine"(they're
within the expected numeric range).

Now, if we pass on a big value to it (2 to the power of 32 divided by 2,
e.g. enough so that signed long int can't hold it without overflowing),
e.g. 'git diff --unified=2147483648 HEAD^', the output will include
(again, just a sample):

@@ -2147483700,4294967295- +2147483700,4294967295- @@

Note that the begin/end line numbers are way out of range. The diff
itself will actually contain no context lines.

Best regards
-- 
Branko Majic
XMPP: branko@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
XMPP: branko@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.
Message 1 of 1 in “[BUG] Integer overflow when supplying large context value to diff --unified”
  1. Branko MajicFeb 9, 2018

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.