diff options
| author | Michael Montalbo <mmontalbo@gmail.com> | 2026-05-12 18:10:22 +0000 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2026-05-13 10:13:26 +0900 |
| commit | 4517e4ca104ca93b51b4acf4d2c62e9325bbb623 (patch) | |
| tree | 4e08b421c3fab2813b343e2883c0015a1bfe8431 /t/t4013/diff.diff_initial..side | |
| parent | 94a9e6934c5978a150de549046e68dad608bcf9f (diff) | |
xdiff: guard against negative context lengths
The xdemitconf_t fields ctxlen and interhunkctxlen are typed as long
(signed), but negative values are not meaningful for context line
counts. Unlike the diff_options fields changed in the previous two
commits, these cannot be converted to unsigned because the xdiff
arithmetic relies on signed subtraction:
s1 = XDL_MAX(xch->i1 - xecfg->ctxlen, 0);
If ctxlen were unsigned long, the signed operand would be implicitly
converted to unsigned, and the subtraction would wrap to a large
positive value when i1 < ctxlen, defeating the XDL_MAX clamp. The
signed type is required for correct context-window calculations.
The previous two commits reject negative values at the parse layer
for --inter-hunk-context and -U/--unified, so negative values should
no longer reach xdiff in normal use. Add BUG() guards at the top of
xdl_get_hunk() as defense in depth to catch programming errors in
current or future callers that bypass option parsing.
xdl_get_hunk() is called by both xdl_emit_diff() and
xdl_call_hunk_func(), so a single guard covers all xdiff consumers.
Signed-off-by: Michael Montalbo <mmontalbo@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t4013/diff.diff_initial..side')
0 files changed, 0 insertions, 0 deletions
