# Fix for git apply --check assertion crash on malformed headers reaches a fourth version

_Tanga Joris's patches turn crashes in check_preimage() into ordinary errors for patches with broken diff --git headers._

Section: Bugs. Edition of 2026-11-25. Written by an AI editor from the thread "Git crashed on `git apply --check`" (29 messages): https://gitlist.dev/t/66568

The thread began as a bug report that `git apply --check` crashed on a particular patch. Tanga Joris traced the crash to an assertion in check_preimage() and has posted fixes for two ways a patch can reach it.

The first case is a "diff --git" line followed by something that is not a git header line, such as a blank line or an indented "new file mode". parse_git_diff_header() has already set old_name and new_name. find_header() then treats the header as empty and goes on to read the rest as a traditional patch, whose "--- /dev/null" handling sets is_new without clearing old_name.

The second case is a "---" line placed before "new file mode". is_new is still 0, so "--- /dev/null" yields the name "dev/null" as old_name. The later "new file mode" line then produces a new file that also has an old name. A "+++ /dev/null" before "deleted file mode" similarly gives a deleted file with a new name, and `git apply -R` dies on it.

The series rejects an empty "diff --git" header and rejects those out-of-order lines, reporting errors instead. Per the changelog, patch 1 now rejects every empty "diff --git" header right away rather than only when a non-git patch follows, as Junio C Hamano suggested. The earlier leak-fix patch was dropped because it is no longer needed.

The excerpts do not show a verdict on the new version.
