]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'rs/xdiff-context-length-fix'
authorJunio C Hamano <gitster@pobox.com>
Sat, 29 Mar 2025 07:39:10 +0000 (16:39 +0900)
committerJunio C Hamano <gitster@pobox.com>
Sat, 29 Mar 2025 07:39:10 +0000 (16:39 +0900)
The xdiff code on 32-bit platform misbehaved when an insanely large
context size is given, which has been corrected.

* rs/xdiff-context-length-fix:
  xdiff: avoid arithmetic overflow in xdl_get_hunk()

1  2 
t/t4055-diff-context.sh
xdiff/xemit.c

Simple merge
diff --cc xdiff/xemit.c
index f8e3f25b03b7f79a60fa5c1418d61970c1360edc,6fc05fc3f3de42995c92fbf6e8742603e57f6207..1d40c9cb4076522d14c87ee115ff7aa354309730
@@@ -52,9 -56,11 +56,11 @@@ static long saturating_add(long a, lon
  xdchange_t *xdl_get_hunk(xdchange_t **xscr, xdemitconf_t const *xecfg)
  {
        xdchange_t *xch, *xchp, *lxch;
-       long max_common = 2 * xecfg->ctxlen + xecfg->interhunkctxlen;
+       long max_common = saturating_add(saturating_add(xecfg->ctxlen,
+                                                       xecfg->ctxlen),
+                                        xecfg->interhunkctxlen);
        long max_ignorable = xecfg->ctxlen;
 -      unsigned long ignored = 0; /* number of ignored blank lines */
 +      long ignored = 0; /* number of ignored blank lines */
  
        /* remove ignorable changes that are too far before other changes */
        for (xchp = *xscr; xchp && xchp->ignore; xchp = xchp->next) {