From b7bc88037fa07dea7ad4c7b0cff496f4664941d2 Mon Sep 17 00:00:00 2001 From: Lorenz Leutgeb Date: Thu, 22 Oct 2026 15:55:12 +0200 Subject: [PATCH] cli: Avoid overflow in `xdiff` on Windows We would like the diff output of changes to the identity document to not collapse into separate hunks, but show all of the identity document in the diff. The way to do this is to set the number of context lines sufficiently high. It turns out that `u32::MAX` is too high for `xdiff`, which is commonly used on Windows. `xdiff` stores the context lines in a signed integer of 32 bits. Also, it appears to double line numbers when it merges hunks. Thus, a safe value seems to be half of `i32::MAX`. --- crates/radicle-cli/src/commands/id.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/radicle-cli/src/commands/id.rs b/crates/radicle-cli/src/commands/id.rs index 9ff38f2bb..845c9bc29 100644 --- a/crates/radicle-cli/src/commands/id.rs +++ b/crates/radicle-cli/src/commands/id.rs @@ -606,7 +606,21 @@ fn print_diff( }; let current = radicle::git::write_tree(&doc::PATH, current.as_bytes(), &repo)?; let mut opts = radicle::git::raw::DiffOptions::new(); - opts.context_lines(u32::MAX); + + { + #[cfg(not(windows))] + const CONTEXT_LINES: u32 = u32::MAX; + + // `xdiff`, which is commonly used on Windows, stores the number of + // context lines as a signed integer and doubles the value when + // merging hunks. Avoid overflow. See also: + // - + // - + #[cfg(windows)] + const CONTEXT_LINES: u32 = (i32::MAX / 2) as u32; + + opts.context_lines(CONTEXT_LINES); + } let diff = repo.diff_tree_to_tree(previous.as_ref(), Some(¤t), Some(&mut opts))?; let diff = Diff::try_from(diff)?;