libansilove

Library for converting ANSI, ASCII, and other formats to PNG
Log | Files | Refs | README | LICENSE

commit 22720f8562ba3e79013c18ddc78cfe79a16ccf09
parent ee4758728171e6809133239a549cbc3ac2330205
Author: Frederic Cambus <fred@statdns.com>
Date:   Thu, 15 Nov 2018 11:46:16 +0100

Add some checks in the ansi sequence parser to avoid out of bound reads

Diffstat:
Msrc/loaders/ansi.c | 6++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/loaders/ansi.c b/src/loaders/ansi.c @@ -143,8 +143,10 @@ int ansilove_ansi(struct ansilove_ctx *ctx, struct ansilove_options *options) loop = ctx->length; break; case ESC: /* ANSi sequence */ - if (next_character == 91) { - for (ansi_sequence_loop = 0; ansi_sequence_loop < ANSI_SEQUENCE_MAX_LENGTH; ansi_sequence_loop++) { + if ((loop+1 < ctx->length) && ctx->buffer[loop + 1] == 91) { + + uint32_t maxlength = fmin(ctx->length - loop, ANSI_SEQUENCE_MAX_LENGTH); + for (ansi_sequence_loop = 0; ansi_sequence_loop < maxlength; ansi_sequence_loop++) { ansi_sequence_character = ctx->buffer[loop + 2 + ansi_sequence_loop]; /* cursor position */