diff options
author | Max Kellermann <max.kellermann@gmail.com> | 2017-12-04 10:34:05 +0100 |
---|---|---|
committer | Max Kellermann <max.kellermann@gmail.com> | 2017-12-04 10:38:33 +0100 |
commit | d714693afa9fe87fa1f0f6a8994aaf0d30f8413c (patch) | |
tree | 29dcadb520426181d6eaf476af730c070f200356 | |
parent | 2465e523fea3598b17e0c96ab63885f6e8aab3a6 (diff) | |
download | pesconvert-d714693afa9fe87fa1f0f6a8994aaf0d30f8413c.tar.gz |
pes: check the color index, fail if out of range
Fixes crash when there are more than 256 blocks.
Signed-off-by: Max Kellermann <max.kellermann@gmail.com>
-rw-r--r-- | pes.c | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -161,7 +161,13 @@ static struct pes_block *new_block(struct pes *pes) struct pes_block *block = calloc(1, sizeof(*block)); if (block) { - block->color = my_colors[pes->nr_colors++]; + unsigned color = pes->nr_colors++; + if (color >= sizeof(my_colors) / sizeof(my_colors[0])) { + free(block); + return NULL; + } + + block->color = my_colors[color]; if (!block->color) { free(block); return NULL; |