summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max.kellermann@gmail.com>2017-12-04 10:34:05 +0100
committerMax Kellermann <max.kellermann@gmail.com>2017-12-04 10:38:33 +0100
commitd714693afa9fe87fa1f0f6a8994aaf0d30f8413c (patch)
tree29dcadb520426181d6eaf476af730c070f200356
parent2465e523fea3598b17e0c96ab63885f6e8aab3a6 (diff)
downloadpesconvert-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.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/pes.c b/pes.c
index 07b2e0d..be7cee9 100644
--- a/pes.c
+++ b/pes.c
@@ -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;