]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0619: integer overflow in popup image size validation v9.2.0619
authorYasuhiro Matsumoto <mattn.jp@gmail.com>
Wed, 10 Jun 2026 21:00:09 +0000 (21:00 +0000)
committerChristian Brabandt <cb@256bit.org>
Wed, 10 Jun 2026 21:00:09 +0000 (21:00 +0000)
Problem:  integer overflow in popup image size validation
          (after v9.2.0612)
Solution: Compute the expected size using a 64-bit varnumber_T
          (Yasuhiro Matsumoto).

The image size validation computed iw * ih * 4 in a 32-bit long, which
overflows on MS-Windows (LLP64) and can wrap to a value that matches a
short blob, so the validation passes and the pixels are later read out
of bounds. Compute the expected size in a 64-bit varnumber_T.

closes: #20463

Signed-off-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/popupwin.c
src/version.c

index 351c8655681123ef806bac79be54017daebac4f4..fdb1d394cdd0245a4d9db705db7e15686a87efda 100644 (file)
@@ -981,9 +981,11 @@ apply_general_options(win_T *wp, dict_T *dict)
        {
            blob_T  *b = id->di_tv.vval.v_blob;
            long     blen = blob_len(b);
-           int      has_alpha = (blen == (long)iw * ih * 4);
+           // 64-bit to avoid iw * ih * 4 overflow on a 32-bit long
+           varnumber_T  npixels = (varnumber_T)iw * ih;
+           int      has_alpha = (blen == npixels * 4);
 
-           if (has_alpha || blen == (long)iw * ih * 3)
+           if (has_alpha || blen == npixels * 3)
            {
                // Detect "same-size image swap": replacing the pixel buffer
                // without changing the popup's pixel dimensions or pixel
index 8d6afb613b24be73ecf9b627cd20ee6ff7f044b1..9159626e3850b55e1efeab41d3b68f5055313562 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    619,
 /**/
     618,
 /**/