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>
{
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
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 619,
/**/
618,
/**/