patch 9.1.1963: diff: missing diff size limit for xdiff
Commit:
https://github.com/vim/vim/commit/4af6d9755cba0dd07e881172f2a6e0efe9986ddc
Author: Yee Cheng Chin <[email protected]>
Date: Tue Dec 9 13:05:17 2025 +0100
patch 9.1.1963: diff: missing diff size limit for xdiff
Problem: diff: missing diff size limit for xdiff
Solution: Impose file size limit for internal diff (xdiff)
(Yee Cheng Chin).
Git imposes a hard cap on file size for content that it passes to xdiff
(added to Git in dcd1742e56e, defined in xdiff-interface.h), due to
integer overflow concerns in xdiff. Vim doesn't specify such a limit
right now, which means it's possible for a user to diff a large file
(1GB+) and trigger these overflow issues.
Add the same size limit (1GB minus 1MB) to Vim and simply throws an
error when Vim encounters files larger than said limit. For now, reuse
the same error message regarding internal diff failures. There is no
need to add the same limit for external diff as it's up to each tool to
error check their input to decide what is appropriate or not.
closes: #18891
Signed-off-by: Yee Cheng Chin <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 03c0c547b..d7adf555a 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -1,4 +1,4 @@
-*options.txt* For Vim version 9.1. Last change: 2025 Nov 27
+*options.txt* For Vim version 9.1. Last change: 2025 Dec 09
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -3202,9 +3202,10 @@ A jump table for the options with a short description
can be found at |Q_op|.
internal Use the internal diff library. This is
ignored when 'diffexpr' is set. *E960*
When running out of memory when writing a
- buffer this item will be ignored for diffs
- involving that buffer. Set the 'verbose'
- option to see when this happens.
+ buffer or the diff is larger than 1 GB this
+ item will be ignored for diffs involving that
+ buffer. Set the 'verbose' option to see when
+ this happens.
iwhite Ignore changes in amount of white space. Adds
the "-b" flag to the "diff" command if
diff --git a/src/diff.c b/src/diff.c
index c15936b12..5f5376133 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -52,6 +52,10 @@ static long diff_algorithm = XDF_INDENT_HEURISTIC;
#define LBUFLEN 50 // length of line in diff file
+// Max file size xdiff is eqipped to deal with. The value (1GB - 1MB) comes
+// from Git's implementation.
+#define MAX_XDIFF_SIZE (1024L * 1024 * 1023)
+
static int diff_a_works = MAYBE; // TRUE when "diff -a" works, FALSE when it
// doesn't work, MAYBE when not checked yet
#if defined(MSWIN)
@@ -1318,6 +1322,12 @@ diff_file_internal(diffio_T *diffio)
emit_cfg.hunk_func = xdiff_out_indices;
else
emit_cb.out_line = xdiff_out_unified;
+ if (diffio->dio_orig.din_mmfile.size > MAX_XDIFF_SIZE ||
+ diffio->dio_new.din_mmfile.size > MAX_XDIFF_SIZE)
+ {
+ emsg(_(e_problem_creating_internal_diff));
+ return FAIL;
+ }
if (xdl_diff(&diffio->dio_orig.din_mmfile,
&diffio->dio_new.din_mmfile,
¶m, &emit_cfg, &emit_cb) < 0)
diff --git a/src/version.c b/src/version.c
index e9ecbef67..6e48a748d 100644
--- a/src/version.c
+++ b/src/version.c
@@ -729,6 +729,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1963,
/**/
1962,
/**/
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1vSwcR-006Q3S-P2%40256bit.org.