)]}'
{
  "commit": "88efab5c3b7b7585a3b4f45db89c108fef9a04f2",
  "tree": "c70bff3a60cc5c96a7756d893bb8efcfd65041a8",
  "parents": [
    "94f057755b7941b321fd11fec1b2e3ca5313a4e0"
  ],
  "author": {
    "name": "Jeff King",
    "email": "peff@peff.net",
    "time": "Wed Jul 15 02:05:23 2026 -0400"
  },
  "committer": {
    "name": "Junio C Hamano",
    "email": "gitster@pobox.com",
    "time": "Wed Jul 15 11:33:50 2026 -0700"
  },
  "message": "diff: ignore unmerged paths outside prefix with --relative --cached\n\nA diff using --relative ignores entries outside the current directory.\nThis results in a segfault when we try to process an unmerged entry\nthat\u0027s outside of our prefix, since we end up with a NULL diff_filepair\nand use it without checking that it\u0027s valid.\n\nI think this bug goes back to 76399c0195 (diff.c: return filepair from\ndiff_unmerge(), 2011-04-22). Prior to that, diff_unmerge() knew to skip\nentries outside of our prefix, due to cd676a5136 (diff --relative:\noutput paths as relative to the current subdirectory, 2008-02-12). Back\nthen the caller didn\u0027t care that we hadn\u0027t added anything to the queue.\nIn 76399c0195 that changed; we now returned the pair (or NULL), and the\ncaller in do_oneway_diff() was then called fill_filespec() itself. And\nit does so without checking for NULL, causing a segfault.\n\nThe obvious fix is to skip the fill_filespec() call (after which we just\nreturn), which this patch does.\n\nThere\u0027s another call to diff_unmerge() in run_diff_files(). That case\nwas already fixed by 8174627b3d (diff-lib: ignore paths that are outside\n$cwd if --relative asked, 2021-08-22), but of course it didn\u0027t help us\nfor --cached.\n\nThat commit also claims that checking the result of diff_unmerge() is\nnot enough, as we\u0027d want other code paths to skip the entry, too (even\nif they wouldn\u0027t segfault). But as far as I can tell, that is not true\nfor --cached. We eventually end up in diff_queue_addremove() or in\ndiff_queue_change(), both of which know to return early when we\u0027re\noutside of the prefix.\n\nArguably we could be checking at the top of oneway_diff() whether the\npath is interesting at all. That would not only avoid this code path\nentirely, but would also possibly save a small amount of work. But since\neverything else appears to work OK, I went for the smallest fix here to\navoid any regression.\n\nSpecifically, a comment in oneway_diff() claims we\u0027re supposed to\nadvance o-\u003epos, which we might fail to do if we return early. Though\nthat \"advance\" seems to have gone away in da165f470e (unpack-trees.c:\nprepare for looking ahead in the index, 2010-01-07), so it is possible\nthe comment is simply out of date.  We can explore that separately;\nchecking for a NULL return from diff_unmerge() seems like a sensible\nthing to do regardless.\n\nWe can piggy-back on the tests added by 8174627b3d; we\u0027re just checking\nthe --cached variant.\n\nSigned-off-by: Jeff King \u003cpeff@peff.net\u003e\nSigned-off-by: Junio C Hamano \u003cgitster@pobox.com\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "ae91027a024eece23f0f1ede20467eeb425a2b3b",
      "old_mode": 33188,
      "old_path": "diff-lib.c",
      "new_id": "a23119b852201270fe2b4e7e91cb726d1ed3249b",
      "new_mode": 33188,
      "new_path": "diff-lib.c"
    },
    {
      "type": "modify",
      "old_id": "2c8493fe66c441b23d11c8ed1048d3a92e3937e8",
      "old_mode": 33261,
      "old_path": "t/t4045-diff-relative.sh",
      "new_id": "167be0bdcce586253de6a695d95c17f552544558",
      "new_mode": 33261,
      "new_path": "t/t4045-diff-relative.sh"
    }
  ]
}
