new file mode 100644
@@ -0,0 +1,235 @@
+From 5a0e9915092ece3be3f7c06b409504c066950585 Mon Sep 17 00:00:00 2001
+From: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
+Date: Fri, 16 Oct 2026 15:30:01 +0530
+Subject: [PATCH] xdiff: use size_t for merge buffer size computations
+
+libxdiff keeps some intermediate size computations in "long" and "int"
+variables and then feeds the result to malloc(). These can overflow,
+especially "int", which is 32 bits even on 64-bit platforms ("long" is
+too, on Windows). Often this is harmless apart from a wrong answer:
+when the same truncated value is passed both to malloc() and to the
+memcpy() that fills the buffer, the copy stays inside the allocation
+and the result is merely truncated.
+
+xdl_fill_merge_buffer() is different. It adds up the output size in an
+int, allocates that much, then writes each piece at "dest + size". The
+sum can overflow because a conflict-marker-size from .gitattributes
+accepts any positive int and is added several times per conflict, and
+because diff3 output of large inputs can exceed INT_MAX.
+
+We considered both ways the sum can wrap:
+
+ 1. It ends up negative. malloc() sees a huge size_t and fails, which
+ is a spurious error but not exploitable.
+
+ 2. It wraps back to a small positive value. malloc() succeeds with a
+ buffer that is too small. Each addend is below 2^31, so the
+ running offset passes through negative values on the way. Writes
+ therefore first run past the end of the buffer and then land
+ before its start.
+
+Convert these variables to size_t. The running sum can then no longer
+go negative, and on 64-bit platforms it can no longer realistically
+wrap either. Two holes remain, which the next commit closes by using
+st_add*(): the marker addends (e.g. "marker_size + 1 + needs_cr +
+marker1_size") are still computed as int and can overflow when
+conflict-marker-size is close to INT_MAX, and on 32-bit platforms
+size_t itself can still wrap.
+
+Note that in xdl_do_merge(), the value returned by xdl_fill_merge_buffer()
+is assigned to mmbuffer_t's size which is a long. This may result in
+silent truncation on LLP64 platforms like Windows, where long is 32 bits.
+Fixing this properly means converting the users of mmbuffer_t, which
+pass its size on to functions taking an unsigned long, and the code
+they call, to size_t. That is a larger effort for a separate series.
+Until then, fail the merge when the result does not fit in a long.
+This turns a silent truncation into an error the caller already
+knows how to handle.
+
+CVE: CVE-2026-105437
+Upstream-Status: Backport [https://github.com/git/git/commit/288266c11d91a01239e8e17f4bd90f1276e30030]
+
+Based-on-patch-by: Jeff King <peff@peff.net>
+Helped-by: Toon Claes <toon@iotcl.com>
+Helped-by: Christian Couder <christian@gitlab.com>
+Signed-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
+Signed-off-by: Ashishkumar Parmar <asparmar@cisco.com>
+---
+ t/t4300-merge-tree.sh | 74 +++++++++++++++++++++++++++++++++++++++++++
+ xdiff/xmerge.c | 45 ++++++++++++++------------
+ 2 files changed, 99 insertions(+), 20 deletions(-)
+
+diff --git a/t/t4300-merge-tree.sh b/t/t4300-merge-tree.sh
+index 27fbe193bc..13e883c491 100755
+--- a/t/t4300-merge-tree.sh
++++ b/t/t4300-merge-tree.sh
+@@ -378,4 +378,78 @@ test_expect_success 'merge-tree respects core.useReplaceRefs=false' '
+ test valid = $merged
+ '
+
++# A couple of tests to ensure merge-tree does not undergo a heap
++# buffer overflow.
++#
++# Number of lines per file, and every Nth line is a conflict site.
++# With N=5 and 2100 lines there are 420 independent conflict hunks per file.
++# We use the specified MARKER_SIZE as it amounts to around 10MiB of conflict
++# hunk text for each conflict in the file. This helps us to quickly trigger
++# the heap buffer overflow with just 420 conflict hunks.
++LINES=2100
++STEP=5
++MARKER_SIZE=3495254
++
++# gen_file <label>: emit a file whose conflict-site lines carry <label>.
++# Context lines between sites contain alphanumerics so that xdiff does not
++# coalesce neighbouring hunks into one large conflict.
++gen_file () {
++ n=1
++ while test $n -le $LINES
++ do
++ if test $(($n % $STEP)) = 0
++ then
++ echo "$1 site $n"
++ else
++ echo "context line $n"
++ fi
++ n=$(($n + 1))
++ done
++}
++
++test_expect_success EXPENSIVE 'setup: base commit with attributes' '
++ echo "big.txt conflict-marker-size=$MARKER_SIZE" >.gitattributes &&
++ gen_file base >big.txt &&
++ gen_file base >other.txt &&
++ git add .gitattributes big.txt other.txt &&
++ git commit -m base &&
++ git branch -M main &&
++
++ git checkout -b side1 main &&
++ gen_file ours >big.txt &&
++ gen_file ours >other.txt &&
++ git commit -a -m side1 &&
++
++ git checkout -b side2 main &&
++ gen_file theirs >big.txt &&
++ gen_file theirs >other.txt &&
++ git commit -a -m side2
++'
++
++# We have LONG_IS_64BIT as a prerequisite since we guard against downcasts
++# from 64-bit size_t to 32-bit long (for example on Windows)
++test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,LONG_IS_64BIT 'no buffer overflow in merge-tree --write-tree' '
++ test_expect_code 1 git merge-tree --write-tree side1 side2 >out &&
++ tree=$(head -n 1 out) &&
++ git cat-file -e "$tree^{tree}"
++'
++
++test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,LONG_IS_64BIT 'conflicted paths are listed without buffer overflow' '
++ test_expect_code 1 git merge-tree --write-tree --name-only \
++ side1 side2 >out &&
++ sed -n "2,\$p" out | sed "/^\$/,\$d" | sort -u >actual &&
++ cat >expect <<-\EOF &&
++ big.txt
++ other.txt
++ EOF
++ test_cmp expect actual
++'
++
++# Ensure we properly identify a downcast from 64-bit size_t to
++# 32-bit long on Windows
++test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT 'merge-tree dies when merge buffer size does not fit long' '
++ test_must_fail git merge-tree --write-tree side1 side2 2>err &&
++ test_grep "failure to merge" err
++'
++
+ test_done
+diff --git a/xdiff/xmerge.c b/xdiff/xmerge.c
+index 29dad98c49..d18c6f30be 100644
+--- a/xdiff/xmerge.c
++++ b/xdiff/xmerge.c
+@@ -109,10 +109,10 @@ static int xdl_merge_cmp_lines(xdfenv_t *xe1, int i1, xdfenv_t *xe2, int i2,
+ return 0;
+ }
+
+-static int xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int needs_cr, int add_nl, char *dest)
++static size_t xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int needs_cr, int add_nl, char *dest)
+ {
+ xrecord_t *recs;
+- int size = 0;
++ size_t size = 0;
+
+ recs = (use_orig ? xe->xdf1.recs : xe->xdf2.recs) + i;
+
+@@ -139,12 +139,12 @@ static int xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int nee
+ return size;
+ }
+
+-static int xdl_recs_copy(xdfenv_t *xe, int i, int count, int needs_cr, int add_nl, char *dest)
++static size_t xdl_recs_copy(xdfenv_t *xe, int i, int count, int needs_cr, int add_nl, char *dest)
+ {
+ return xdl_recs_copy_0(0, xe, i, count, needs_cr, add_nl, dest);
+ }
+
+-static int xdl_orig_copy(xdfenv_t *xe, int i, int count, int needs_cr, int add_nl, char *dest)
++static size_t xdl_orig_copy(xdfenv_t *xe, int i, int count, int needs_cr, int add_nl, char *dest)
+ {
+ return xdl_recs_copy_0(1, xe, i, count, needs_cr, add_nl, dest);
+ }
+@@ -193,11 +193,11 @@ static int is_cr_needed(xdfenv_t *xe1, xdfenv_t *xe2, xdmerge_t *m)
+ return needs_cr < 0 ? 0 : needs_cr;
+ }
+
+-static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
+- xdfenv_t *xe2, const char *name2,
+- const char *name3,
+- int size, int i, int style,
+- xdmerge_t *m, char *dest, int marker_size)
++static size_t fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
++ xdfenv_t *xe2, const char *name2,
++ const char *name3,
++ size_t size, int i, int style,
++ xdmerge_t *m, char *dest, int marker_size)
+ {
+ int marker1_size = (name1 ? strlen(name1) + 1 : 0);
+ int marker2_size = (name2 ? strlen(name2) + 1 : 0);
+@@ -280,14 +280,15 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
+ return size;
+ }
+
+-static int xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1,
+- xdfenv_t *xe2, const char *name2,
+- const char *ancestor_name,
+- int favor,
+- xdmerge_t *m, char *dest, int style,
+- int marker_size)
++static size_t xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1,
++ xdfenv_t *xe2, const char *name2,
++ const char *ancestor_name,
++ int favor,
++ xdmerge_t *m, char *dest, int style,
++ int marker_size)
+ {
+- int size, i;
++ size_t size;
++ int i;
+
+ for (size = i = 0; m; m = m->next) {
+ if (favor && !m->mode)
+@@ -664,10 +665,14 @@ static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1,
+ /* output */
+ if (result) {
+ int marker_size = xmp->marker_size;
+- int size = xdl_fill_merge_buffer(xe1, name1, xe2, name2,
+- ancestor_name,
+- favor, changes, NULL, style,
+- marker_size);
++ size_t size = xdl_fill_merge_buffer(xe1, name1, xe2, name2,
++ ancestor_name,
++ favor, changes, NULL, style,
++ marker_size);
++ if (size > LONG_MAX) {
++ xdl_cleanup_merge(changes);
++ return -1;
++ }
+ result->ptr = xdl_malloc(size);
+ if (!result->ptr) {
+ xdl_cleanup_merge(changes);
new file mode 100644
@@ -0,0 +1,211 @@
+From 101cf0f0ac86c6f0ffa6866cd139db2253af84b4 Mon Sep 17 00:00:00 2001
+From: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
+Date: Fri, 16 Oct 2026 15:30:02 +0530
+Subject: [PATCH] xdiff: check for overflow when computing merge buffer size
+
+The previous commit switched the merge buffer size computation in
+xdl_fill_merge_buffer() and its helpers to size_t. That keeps the
+running sum from going negative, but two ways to overflow remain.
+
+First, the conflict marker addends (e.g. "marker_size + 1 + needs_cr +
+marker1_size") are still summed as int before being added to "size".
+When conflict-marker-size is close to INT_MAX, that int sum overflows
+and goes negative. Converted to size_t and added, it makes "size"
+smaller instead of larger, even on 64-bit platforms.
+
+Second, on platforms where size_t is 32 bits, the running sum itself
+can still wrap, for example with a large conflict-marker-size.
+
+Either way, malloc() returns a buffer that is too small, and the
+write pass, which replays the same sum, runs past its end.
+
+Use the st_add*() helpers to sum the sizes, adding each marker addend
+separately, so an overflow dies instead of silently wrapping.
+
+Note that in fill_conflict_hunk() we do not cover all manipulations of
+"size"; that's because the function is called twice: once with a NULL
+dest to compute the size, and the second time to fill it (with the
+assumption that the caller gave us "size" bytes). We need only perform
+the overflow checks on the first round.
+
+CVE: CVE-2026-105437
+Upstream-Status: Backport [https://github.com/git/git/commit/b1313872cefef5704a0acff14b7c0869a9d5dc7c]
+
+Backport Changes:
+- Keep Git 2.53.0's struct-based records. Remove the record-length
+ and final record-count casts to match Git 2.53.1.
+- Fold the required st_add5() helper from upstream commit [1],
+ which is absent in Git 2.53.0.
+
+[1] https://github.com/git/git/commit/0dc3b5c0224b985e48be513330f8d79e87db9a12
+
+Based-on-patch-by: Jeff King <peff@peff.net>
+Signed-off-by: Kaartic Sivaraam <kaartic.sivaraam@gmail.com>
+Signed-off-by: Ashishkumar Parmar <asparmar@cisco.com>
+---
+ git-compat-util.h | 1 +
+ t/t4300-merge-tree.sh | 9 +++++++++
+ xdiff/xmerge.c | 46 +++++++++++++++++++++----------------------
+ 3 files changed, 33 insertions(+), 23 deletions(-)
+
+diff --git a/git-compat-util.h b/git-compat-util.h
+index bebcf9f698..43fa765a44 100644
+--- a/git-compat-util.h
++++ b/git-compat-util.h
+@@ -614,6 +614,7 @@ static inline size_t st_add(size_t a, size_t b)
+ }
+ #define st_add3(a,b,c) st_add(st_add((a),(b)),(c))
+ #define st_add4(a,b,c,d) st_add(st_add3((a),(b),(c)),(d))
++#define st_add5(a,b,c,d,e) st_add(st_add4((a),(b),(c),(d)),(e))
+
+ static inline size_t st_mult(size_t a, size_t b)
+ {
+diff --git a/t/t4300-merge-tree.sh b/t/t4300-merge-tree.sh
+index 13e883c491..41386d6025 100755
+--- a/t/t4300-merge-tree.sh
++++ b/t/t4300-merge-tree.sh
+@@ -386,6 +386,10 @@ test_expect_success 'merge-tree respects core.useReplaceRefs=false' '
+ # We use the specified MARKER_SIZE as it amounts to around 10MiB of conflict
+ # hunk text for each conflict in the file. This helps us to quickly trigger
+ # the heap buffer overflow with just 420 conflict hunks.
++#
++# The merged file comes out at just over 4GiB. On 64-bit builds merge-tree
++# must produce it. On 32-bit builds it cannot fit in size_t, so merge-tree
++# must die instead of wrapping the size and overflowing the buffer.
+ LINES=2100
+ STEP=5
+ MARKER_SIZE=3495254
+@@ -452,4 +456,9 @@ test_expect_success EXPENSIVE,SIZE_T_IS_64BIT,!LONG_IS_64BIT 'merge-tree dies wh
+ test_grep "failure to merge" err
+ '
+
++test_expect_success EXPENSIVE,!SIZE_T_IS_64BIT 'merge-tree dies when merge buffer size overflows size_t' '
++ test_must_fail git merge-tree --write-tree side1 side2 2>err &&
++ test_grep "size_t overflow" err
++'
++
+ test_done
+diff --git a/xdiff/xmerge.c b/xdiff/xmerge.c
+index d18c6f30be..9844449a8e 100644
+--- a/xdiff/xmerge.c
++++ b/xdiff/xmerge.c
+@@ -119,7 +119,7 @@ static size_t xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int
+ if (count < 1)
+ return 0;
+
+- for (i = 0; i < count; size += (int)recs[i++].size)
++ for (i = 0; i < count; size = st_add(size, recs[i++].size))
+ if (dest)
+ memcpy(dest + size, recs[i].ptr, recs[i].size);
+ if (add_nl) {
+@@ -128,12 +128,12 @@ static size_t xdl_recs_copy_0(int use_orig, xdfenv_t *xe, int i, int count, int
+ if (needs_cr) {
+ if (dest)
+ dest[size] = '\r';
+- size++;
++ size = st_add(size, 1);
+ }
+
+ if (dest)
+ dest[size] = '\n';
+- size++;
++ size = st_add(size, 1);
+ }
+ }
+ return size;
+@@ -208,11 +208,11 @@ static size_t fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
+ marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
+
+ /* Before conflicting part */
+- size += xdl_recs_copy(xe1, i, m->i1 - i, 0, 0,
+- dest ? dest + size : NULL);
++ size = st_add(size, xdl_recs_copy(xe1, i, m->i1 - i, 0, 0,
++ dest ? dest + size : NULL));
+
+ if (!dest) {
+- size += marker_size + 1 + needs_cr + marker1_size;
++ size = st_add5(size, marker_size, 1, needs_cr, marker1_size);
+ } else {
+ memset(dest + size, '<', marker_size);
+ size += marker_size;
+@@ -227,13 +227,13 @@ static size_t fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
+ }
+
+ /* Postimage from side #1 */
+- size += xdl_recs_copy(xe1, m->i1, m->chg1, needs_cr, 1,
+- dest ? dest + size : NULL);
++ size = st_add(size, xdl_recs_copy(xe1, m->i1, m->chg1, needs_cr, 1,
++ dest ? dest + size : NULL));
+
+ if (style == XDL_MERGE_DIFF3 || style == XDL_MERGE_ZEALOUS_DIFF3) {
+ /* Shared preimage */
+ if (!dest) {
+- size += marker_size + 1 + needs_cr + marker3_size;
++ size = st_add5(size, marker_size, 1, needs_cr, marker3_size);
+ } else {
+ memset(dest + size, '|', marker_size);
+ size += marker_size;
+@@ -246,12 +246,12 @@ static size_t fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
+ dest[size++] = '\r';
+ dest[size++] = '\n';
+ }
+- size += xdl_orig_copy(xe1, m->i0, m->chg0, needs_cr, 1,
+- dest ? dest + size : NULL);
++ size = st_add(size, xdl_orig_copy(xe1, m->i0, m->chg0, needs_cr, 1,
++ dest ? dest + size : NULL));
+ }
+
+ if (!dest) {
+- size += marker_size + 1 + needs_cr;
++ size = st_add4(size, marker_size, 1, needs_cr);
+ } else {
+ memset(dest + size, '=', marker_size);
+ size += marker_size;
+@@ -261,10 +261,10 @@ static size_t fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
+ }
+
+ /* Postimage from side #2 */
+- size += xdl_recs_copy(xe2, m->i2, m->chg2, needs_cr, 1,
+- dest ? dest + size : NULL);
++ size = st_add(size, xdl_recs_copy(xe2, m->i2, m->chg2, needs_cr, 1,
++ dest ? dest + size : NULL));
+ if (!dest) {
+- size += marker_size + 1 + needs_cr + marker2_size;
++ size = st_add5(size, marker_size, 1, needs_cr, marker2_size);
+ } else {
+ memset(dest + size, '>', marker_size);
+ size += marker_size;
+@@ -301,25 +301,25 @@ static size_t xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1,
+ marker_size);
+ else if (m->mode & 3) {
+ /* Before conflicting part */
+- size += xdl_recs_copy(xe1, i, m->i1 - i, 0, 0,
+- dest ? dest + size : NULL);
++ size = st_add(size, xdl_recs_copy(xe1, i, m->i1 - i, 0, 0,
++ dest ? dest + size : NULL));
+ /* Postimage from side #1 */
+ if (m->mode & 1) {
+ int needs_cr = is_cr_needed(xe1, xe2, m);
+
+- size += xdl_recs_copy(xe1, m->i1, m->chg1, needs_cr, (m->mode & 2),
+- dest ? dest + size : NULL);
++ size = st_add(size, xdl_recs_copy(xe1, m->i1, m->chg1, needs_cr, (m->mode & 2),
++ dest ? dest + size : NULL));
+ }
+ /* Postimage from side #2 */
+ if (m->mode & 2)
+- size += xdl_recs_copy(xe2, m->i2, m->chg2, 0, 0,
+- dest ? dest + size : NULL);
++ size = st_add(size, xdl_recs_copy(xe2, m->i2, m->chg2, 0, 0,
++ dest ? dest + size : NULL));
+ } else
+ continue;
+ i = m->i1 + m->chg1;
+ }
+- size += xdl_recs_copy(xe1, i, (int)xe1->xdf2.nrec - i, 0, 0,
+- dest ? dest + size : NULL);
++ size = st_add(size, xdl_recs_copy(xe1, i, xe1->xdf2.nrec - i, 0, 0,
++ dest ? dest + size : NULL));
+ return size;
+ }
+
@@ -10,6 +10,8 @@ PROVIDES:append:class-native = " git-replacement-native"
SRC_URI = "${KERNELORG_MIRROR}/software/scm/git/git-${PV}.tar.gz;name=tarball \
file://fixsort.patch \
file://0001-config.mak.uname-do-not-force-RHEL-7-specific-build-.patch \
+ file://CVE-2026-105437_p1.patch \
+ file://CVE-2026-105437_p2.patch \
"
SRC_URI:append:class-nativesdk = " \