Use snprintf instead of sprintf

This is fix for CVE-2021-34552

(cherry picked from commit 518ee3722a)
This commit is contained in:
wooken 2022-02-14 13:41:08 -08:00
parent 04db0b815b
commit 59770927ce
2 changed files with 19 additions and 11 deletions

View File

@ -2,6 +2,12 @@
Changelog (Pillow)
==================
6.2.2.3 (2022-02-14)
--------------------
- Use snprintf instead of sprintf. CVE-2021-34552
[wooken]
6.2.2.2 (date TBD)
------------------

View File

@ -1618,17 +1618,15 @@ convert(Imaging imOut, Imaging imIn, const char *mode,
break;
}
if (!convert)
if (!convert) {
#ifdef notdef
return (Imaging) ImagingError_ValueError("conversion not supported");
#else
{
static char buf[256];
/* FIXME: may overflow if mode is too large */
sprintf(buf, "conversion from %s to %s not supported", imIn->mode, mode);
return (Imaging) ImagingError_ValueError(buf);
}
static char buf[100];
snprintf(buf, 100, "conversion from %.10s to %.10s not supported", imIn->mode, mode);
return (Imaging)ImagingError_ValueError(buf);
#endif
}
imOut = ImagingNew2Dirty(mode, imOut, imIn);
if (!imOut)
@ -1681,10 +1679,14 @@ ImagingConvertTransparent(Imaging imIn, const char *mode,
}
#else
{
static char buf[256];
/* FIXME: may overflow if mode is too large */
sprintf(buf, "conversion from %s to %s not supported in convert_transparent", imIn->mode, mode);
return (Imaging) ImagingError_ValueError(buf);
static char buf[100];
snprintf(
buf,
100,
"conversion from %.10s to %.10s not supported in convert_transparent",
imIn->mode,
mode);
return (Imaging)ImagingError_ValueError(buf);
}
#endif