commit 1c3e5c6c79a2fc840ef28b78f93a433ce3d2659e
parent c6f1bdeef64b60bc9d647e9fb57597dd60f0c4e5
Author: Frederic Cambus <fred@statdns.com>
Date: Mon, 15 Oct 2018 13:08:02 +0200
Check that loop < ctx->length instead, to avoid out of bound reads
Diffstat:
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/src/loaders/binary.c b/src/loaders/binary.c
@@ -57,19 +57,23 @@ int ansilove_binary(struct ansilove_ctx *ctx, struct ansilove_options *options)
}
character = ctx->buffer[loop];
- attribute = ctx->buffer[loop+1];
+
+ if (ctx->length > loop) {
+ attribute = ctx->buffer[loop+1];
- background = (attribute & 240) >> 4;
- foreground = (attribute & 15);
+ background = (attribute & 240) >> 4;
+ foreground = (attribute & 15);
- if (background > 8 && !options->icecolors)
- background -= 8;
+ if (background > 8 && !options->icecolors)
+ background -= 8;
- drawchar(canvas, fontData.font_data, options->bits, fontData.height,
- column, row, colors[background], colors[foreground], character);
+ drawchar(canvas, fontData.font_data, options->bits,
+ fontData.height, column, row, colors[background],
+ colors[foreground], character);
- column++;
- loop += 2;
+ column++;
+ loop += 2;
+ }
}
// create output image