From: Junio C Hamano Date: Sat, 29 Mar 2025 07:39:10 +0000 (+0900) Subject: Merge branch 'rs/xdiff-context-length-fix' X-Git-Tag: v2.50.0-rc0~160 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6767149eca352db846ae065fa67614a1b4bc45a6;p=thirdparty%2Fgit.git Merge branch 'rs/xdiff-context-length-fix' 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() --- 6767149eca352db846ae065fa67614a1b4bc45a6 diff --cc xdiff/xemit.c index f8e3f25b03,6fc05fc3f3..1d40c9cb40 --- a/xdiff/xemit.c +++ b/xdiff/xemit.c @@@ -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) {