
PoC and lab for CVE-2026-105437, a 32-bit integer overflow in Git's xdiff three-way merge causing a heap buffer overflow via git merge-tree and conflict-marker-size.
| CVE | CVE-2026-105437 |
| Component | Git — three-way merge machinery, xdiff/xmerge.c (xdl_fill_merge_buffer()) |
| Affected | Git ≤ 2.56.0 (and the 2.50 – 2.55 series) |
| Fixed in | Git 2.56.1, and 2.50.2 / 2.51.3 / 2.52.1 / 2.53.1 / 2.54.1 / 2.55.1 |
| CWE | CWE-190 (integer overflow) leading to CWE-787 (out-of-bounds write) |
| Impact | Heap buffer overflow (out-of-bounds write) while merging attacker-controlled content |
| Vector | git merge-tree --write-tree, i.e. the mergeability check of a merge request |
| Trigger | A committed .gitattributes carrying conflict-marker-size=<huge> plus a merge that produces many conflicts |
Any user who can push a branch to a repository and open a merge request can
crash the hosting service's merge machinery. Git computes the size of the
merge output buffer in a 32-bit int; with enough conflicts and a large
conflict-marker-size attribute the accumulator wraps around, malloc()
returns a buffer that is far too small, and the merge result is written past
the end of it.
GitLab, which assigned the CVE, named git merge-tree as the primary
attack surface — a hosting server runs it to decide whether a merge request
can be merged. A user only needs to commit a .gitattributes file and push
a branch.
Beyond the overflow itself, this repository documents a defect in the
mitigation GitLab published with the advisory: the info/attributes
workaround does not work as written and leaves the service exposed.
Before writing a merge result, Git computes how large the output buffer has
to be. In xdiff/xmerge.c (Git 2.56.0):
static int fill_conflict_hunk(..., int size, ..., int marker_size)
{
...
if (!dest) {
size += marker_size + 1 + needs_cr + marker1_size; /* (1) */
} else {
memset(dest + size, '<', marker_size);
size += marker_size;
...
}
...
if (!dest) {
size += marker_size + 1 + needs_cr; /* (2) */
} else {
memset(dest + size, '=', marker_size);
...
}
...
if (!dest) {
size += marker_size + 1 + needs_cr + marker2_size; /* (3) */
} else {
memset(dest + size, '>', marker_size);
...
}
return size;
}
static int xdl_fill_merge_buffer(..., int marker_size)
{
int size, i; /* <-- 32-bit accumulator */
for (size = i = 0; m; m = m->next) {
...
size = fill_conflict_hunk(..., size, ..., marker_size);
}
...
}
and allocates exactly that many bytes:
/* xdl_do_merge() */
int size = xdl_fill_merge_buffer(xe1, name1, xe2, name2,
ancestor_name, favor, changes, NULL, style,
marker_size);
result->ptr = xdl_malloc(size);
...
/* second pass: write into the buffer */
xdl_fill_merge_buffer(xe1, name1, xe2, name2, ancestor_name, favor, changes,
result->ptr, style, marker_size);
The accumulator is an int (32-bit), while the addends that matter are
marker_size bytes per marker, and<<<<<<<, =======, >>>>>>>).marker_size comes from the conflict-marker-size git attribute, read
straight out of the repository's .gitattributes
(merge-ll.c:ll_merge_marker_size() → strtol_i() into an int, with no
upper bound other than INT_MAX).
With N conflict hunks and a marker size M the total is roughly
3 * N * M bytes. Once that exceeds INT_MAX the accumulator wraps:
malloc() receives a huge size_t, the
allocation fails and Git reports a spurious out-of-memory error;malloc() succeeds with
a buffer that is far too small, and the writing pass walks past the end of
the allocation → heap buffer overflow.The upstream fix (Git 2.56.1) converts the accumulator and all addends to
size_t and uses checked arithmetic (st_add(), st_add5()):
288266c11d91 xdiff: use size_t for merge buffer size computations
b1313872cefe xdiff: check for overflow when computing merge buffer size
0dc3b5c0224b git-compat-util: add st_add5() helper to detect size_t overflow
==1386014==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x7b85df1fe9fb
WRITE of size 3495254 at 0x7b85df1fe9fb thread T0
#0 memset
#1 fill_conflict_hunk xdiff/xmerge.c:269
#2 xdl_fill_merge_buffer xdiff/xmerge.c:297
#3 xdl_do_merge xdiff/xmerge.c:671
#4 xdl_merge xdiff/xmerge.c:726
#5 ll_xdl_merge merge-ll.c:144
#6 ll_merge merge-ll.c:448
#7 merge_3way merge-ort.c:2161
#8 handle_content_merge merge-ort.c:2260
#9 process_entry merge-ort.c:4345
#10 process_entries merge-ort.c:4566
#11 merge_ort_nonrecursive_internal merge-ort.c:5288
#12 merge_ort_internal merge-ort.c:5390
#13 merge_incore_recursive merge-ort.c:5449
#14 real_merge builtin/merge-tree.c:490
#15 cmd_merge_tree builtin/merge-tree.c:696
0x7b85df1fe9fb is located 0 bytes to the right of 109108118-byte region
SUMMARY: AddressSanitizer: heap-buffer-overflow xdiff/xmerge.c:269 in fill_conflict_hunk
GitLab's advisory names git merge-tree as the primary vector:
"GitLab, which assigned CVE-2026-105437, said code-hosting servers are most likely to be targeted through git merge-tree. A server may run that command to check whether a pull or merge request can be merged."
and:
"The conflict-marker-size attribute can be set in a .gitattributes file committed to a repository. If a server reads attributes from the repository, any user who can push branches and open a pull or merge request can trigger the flaw."
The flow:
attacker (any user who can push) hosting service (Gitaly)
───────────────────────────────────────── ────────────────────────────────
1. commit .gitattributes: 4. merge request opened /
big.txt conflict-marker-size=3495254 mergeability check
2. push main / feature/ours / feature/theirs 5. git merge-tree --write-tree \
3. open a merge request feature/ours feature/theirs
6. GIT_ATTR_SOURCE points at the
repository tree, so the
committed .gitattributes is
honoured
7. *** heap buffer overflow ***
GIT_ATTR_SOURCE is how a server running against a bare repository makes
Git read .gitattributes out of the repository tree instead of a working
tree — this is what Gitaly does.
GitLab's advisory says:
"As a workaround for this flaw, servers that cannot upgrade yet can add
conflict-marker-size=7to each repository'sinfo/attributesfile, or turn off those merge checks for untrusted repositories."
That workaround does not prevent the crash. Measured against Git 2.56.0:
info/attributes content | result |
|---|---|
conflict-marker-size=7 (exactly as published) | still crashes (SIGSEGV) |
big.txt conflict-marker-size=7 (per-path form) | blocked, merge completes |
The reason is how Git parses an attribute line without a path pattern. In
attr.c:parse_attr_line() the text before the first blank is taken as the
attribute name, so the line
conflict-marker-size=7