]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1963: diff: missing diff size limit for xdiff v9.1.1963
authorYee Cheng Chin <ychin.git@gmail.com>
Tue, 9 Dec 2025 12:05:17 +0000 (13:05 +0100)
committerChristian Brabandt <cb@256bit.org>
Tue, 9 Dec 2025 12:05:17 +0000 (13:05 +0100)
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 <ychin.git@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/options.txt
src/diff.c
src/version.c

index 03c0c547bba7899c23453d17610dbad5bfaa4bcd..d7adf555ab8d41e40d3bb766ebaa3c6b421398c3 100644 (file)
@@ -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
index c15936b12677961bcfbcc46a8f5477a2a3041551..5f5376133e8f5721fc24b1a49f7286520b1ec05b 100644 (file)
@@ -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,
                &param, &emit_cfg, &emit_cb) < 0)
index e9ecbef67f30e7a63e0b6c5759a4ac1ff527c0d7..6e48a748dba32be04253f187bd40c92b2dc94867 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1963,
 /**/
     1962,
 /**/