Skip to content

Commit

Permalink
Handle integer overflow caused by bogus client data
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Higerd committed Feb 14, 2024
1 parent ca6e594 commit 1e3a682
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions openbox/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -2241,15 +2241,20 @@ void client_update_icons(ObClient *self)
while (i + 2 < num) { /* +2 is to make sure there is a w and h */
w = data[i++];
h = data[i++];
/* calculate the data size as guint64 to prevent integer
overflow due to invalid data */
guint64 size = w * h;
/* watch for the data being too small for the specified size,
or for zero sized icons. */
if (i + w*h > num || w == 0 || h == 0) {
i += w*h;
or for zero sized icons */
if (i + size > num || size < w || size < h) {
break;
} else if (w == 0 || h == 0) {
i += size;
continue;
}

/* convert it to the right bit order for ObRender */
for (j = 0; j < w*h; ++j)
for (j = 0; j < size; ++j)
data[i+j] =
(((data[i+j] >> 24) & 0xff) << RrDefaultAlphaOffset) +
(((data[i+j] >> 16) & 0xff) << RrDefaultRedOffset) +
Expand All @@ -2262,7 +2267,7 @@ void client_update_icons(ObClient *self)
else
RrImageAddFromData(img, &data[i], w, h);

i += w*h;
i += size;
}

g_free(data);
Expand Down

0 comments on commit 1e3a682

Please sign in to comment.