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

Re: [PATCH v2] diff: fix out-of-bounds reads and NULL deref in diffstat UTF-8 truncation

From
Elijah Newren <newren@gmail.com>
Date
Apr 20, 2026, 14:51 UTC
Message-ID
<CABPp-BHgnyS_SB6SX1dzAezfExomHts1t02+qr+duCPW6sk1nQ@mail.gmail.com>
In-Reply-To
<aeVqqsdq9B7GE9gS@lorenzo-VM>

On Sun, Apr 19, 2026 at 4:52 PM Lorenzo Pegorari <lorenzo.pegorari2002@gmail.com> wrote:

Show 31 quoted lines
>
> > +test_expect_success FUNNYNAMES 'diffstat truncation with control chars does not crash' '
> > +     FNAME=$(printf "aaa-\x01-aaa") &&
> > +     git commit --allow-empty -m setup &&
> > +     >$FNAME &&
> > +     git add -- $FNAME &&
> > +     git commit -m "add file with control char name" &&
> > +     git -c core.quotepath=false diff --stat --stat-name-width=5 HEAD~1..HEAD >output &&
> > +     test_grep "| 0" output &&
> > +     rm -- $FNAME &&
> > +     git rm -- $FNAME &&
> > +     git commit -m "remove test file"
> > +'
> > +
> >  test_done
>
> The only thing that I don't quite understand is this second test.
>
> From my tests, the previous code using:
>
> ```
> [...]
> while (name_len > len)
>         name_len -= utf8_width((const char**)&name, NULL);
> [...]
> ```
>
> passes this second test just fine, while I believe it's supposed to
> fail.
>
> Am I missing something?
Sorry, I did two things wrong -- I forgot to specify that the second
test only fails under ASan, and I simplified the test too much such
that it doesn't fail under ASan without the fixes (and simplified in
three wrong ways: not enough control characters, wrong kind of control
character, attempting to use hex control code to printf instead of
octal) and apparently forgot to re-check afterwards.  Using the
filename
    FNAME=$(printf "aaa-\302\237\302\237\302\237-aaa") &&
will trigger the out-of-bounds read under ASan before the fixes;
removing the final \302\237 will make it pass with or without the code
fixes.  I'll correct the patch and send in a new round.
Thanks for checking closely.
Previous: Lorenzo PegorariNext: Elijah Newren via GitGitGadget
Message 7 of 9 in “diff: fix out-of-bounds reads and NULL deref in diffstat UTF-8 truncation”
  1. diff: fix out-of-bounds reads and NULL deref in diffstat UTF-8 truncationElijah Newren via GitGitGadget, Apr 17, 2026
  2. Junio C HamanoApr 17, 2026
  3. Elijah NewrenApr 17, 2026
  4. Junio C HamanoApr 17, 2026
  5. diff: fix out-of-bounds reads and NULL deref in diffstat UTF-8 truncationElijah Newren via GitGitGadget, Apr 17, 2026
  6. Lorenzo PegorariApr 19, 2026
  7. Elijah NewrenApr 20, 2026
  8. diff: fix out-of-bounds reads and NULL deref in diffstat UTF-8 truncationElijah Newren via GitGitGadget, Apr 20, 2026
  9. Junio C HamanoApr 20, 2026

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.