git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 17:00 UTC

[PATCH v2 0/2] packfile: fix corruption due to stale delta base cache entries

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 6, 2026, 10:20 UTC
Message-ID
<20261006-pks-packfile-stale-delta-base-cache-v2-0-69669a2fc6ce@pks.im>
In-Reply-To
<20261002-pks-packfile-stale-delta-base-cache-v1-0-7592a3e31ae0@pks.im>
Hi,
this small patch series fixes the bug reported in [1].

To summarize: we never evict delta base cache entries when closing the owning pack. The cache may thus contain stale entries which are keyed by by the memory address of `struct packed_git` and the offset of the entry in the packfile. Now when allocating a new pack that happens to have the exact same address and that has entries sitting at the same offset, we may try to use these stale entries and thus yield corrupted data.

This all sounds very unlikely, but the interesting part is that this can be reproduced by using recursive merges with submodules, as we open and close the object databases of each respective submodule. And if they have similar packfiles, then we may trigger the bug.

The series is built on top of v2.56.0.
Changes in v2:
  - Commit message improvements.
  - Link to v1: https://patch.msgid.link/20261002-pks-packfile-stale-delta-base-cache-v1-0-7592a3e31ae0@pks.im
Thanks!
Patrick
[1]: <CAP4DsUexEmm1qo6jH+Qzy+n3dQs_OCJ8yg=ReF+aVrcTrC7NeQ@mail.gmail.com>
---
Patrick Steinhardt (2):
      packfile: move around `close_pack()`
      packfile: fix corruption due to stale delta base cache entries
 packfile.c                 | 33 ++++++++++++++++++++++----------
 t/t6437-submodule-merge.sh | 47 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 10 deletions(-)
Range-diff versus v1:
1:  e7c340df39 ! 1:  a8af6a79c7 packfile: move around `close_pack()`
    @@ Commit message
         packfile: move around `close_pack()`
     
         In the next commit we'll want to access the delta base cache in
    -    `close_pack()`. Move the function after the declaration of the cache to
    -    prepare for this.
    +    `close_pack()`. Move the function after the declaration of the cache so
    +    that we won't need a forward declaration.
     
         Signed-off-by: Patrick Steinhardt <ps@pks.im>
     
2:  25efe15034 ! 2:  d6d45b5bf9 packfile: fix corruption due to stale delta base cache entries
    @@ Commit message
         would have the exact same key.
     
         All of this sounds very theoretical, but we can actually trigger this
    -    bug somewhat reliably! When doing a merge with "--recurse-submodules" in
    -    a repository with lots of submodules that have similar-looking packfiles
    -    we end up opening and then closing the object databases of each of the
    -    submodules in sequence. Because of the above mentioned commit we would
    -    close and free each of the packfiles part of the respective databases,
    -    but we wouldn't evict thire delta base entries from the cache.
    +    bug somewhat reliably! When doing a merge in a repository with lots of
    +    submodules that have similar-looking packfiles we end up opening and
    +    then closing the object databases of each of the submodules in sequence.
    +    Because of the above mentioned commit we would close and free each of
    +    the packfiles part of the respective databases, but we wouldn't evict
    +    their delta base entries from the cache.
     
         When using glibc, one of the packfiles will eventually get the exact
         same address, and that will then cause Git to read the wrong entry from

--- base-commit: a018953688f1b10bddf91bff8747068f5f4746a4 change-id: 20261002-pks-packfile-stale-delta-base-cache-0d4730487643

Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 12 of 17 in “packfile: fix corruption due to stale delta base cache entries”
  1. 0/2 packfile: fix corruption due to stale delta base cache entriesPatrick Steinhardt, Oct 2, 2026
  2. 1/2 packfile: move around `close_pack()`Patrick Steinhardt, Oct 2, 2026
  3. 2/2 packfile: fix corruption due to stale delta base cache entriesPatrick Steinhardt, Oct 2, 2026
  4. Guillaume ChauvelOct 2, 2026
  5. Philippe BlainOct 2, 2026
  6. Mark C. Chu-CarrollOct 2, 2026
  7. Patrick SteinhardtOct 2, 2026
  8. Patrick SteinhardtOct 2, 2026
  9. Patrick SteinhardtOct 2, 2026
  10. Jeff KingOct 2, 2026
  11. Patrick SteinhardtOct 5, 2026
  12. 0/2 packfile: fix corruption due to stale delta base cache entriesPatrick Steinhardt, Oct 6, 2026
  13. 1/2 packfile: move around `close_pack()`Patrick Steinhardt, Oct 6, 2026
  14. 2/2 packfile: fix corruption due to stale delta base cache entriesPatrick Steinhardt, Oct 6, 2026
  15. Junio C HamanoOct 6, 2026
  16. Patrick SteinhardtOct 7, 2026
  17. Jeff KingOct 7, 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.