Skip to content

Commit

Permalink
check u->width is non-zero and implement stricter integer overflow check
Browse files Browse the repository at this point in the history
  • Loading branch information
iwashiira committed May 30, 2024
1 parent 1e0953f commit b4c5d28
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/misc/upng.c
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,11 @@ lws_upng_decode(lws_upng_t* u, const uint8_t **_pos, size_t *_size)
u->u.y = 0;
u->u.ibp = 0;
u->u.bypp = (u->u.bpp + 7) / 8;
if (!u->width) {
lwsl_err("%s: u->width > 0 is required",
__func__);
return LWS_SRET_FATAL + 27;
}
u->inf.bypl = u->u.bypl = u->width * u->u.bypp;

u->inf.outlen = u->inf.info_size;
Expand All @@ -484,7 +489,7 @@ lws_upng_decode(lws_upng_t* u, const uint8_t **_pos, size_t *_size)
if (!u->inf.out) {
size_t ims = (u->u.bypl * 2) + u->inf.info_size;

if (u->inf.info_size > ims) {
if (u->u.bypl > UINT_MAX / 2 || u->inf.info_size > UINT_MAX - (u->u.bypl * 2)) {
lwsl_err("%s: integer overflow occur in ims %llu",
__func__, (unsigned long long)ims);
return LWS_SRET_FATAL + 27;
Expand Down

0 comments on commit b4c5d28

Please sign in to comment.