libansilove

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

commit 40ecff56b1af844cf0a9a1893afe3ed1354d2784
parent 3c3083487455d5ee5d6af5e4a20f315e14ed2b02
Author: Frederic Cambus <fred@statdns.com>
Date:   Wed, 12 Dec 2018 15:04:40 +0100

Add format validation checks for the XBin loader

Diffstat:
MTODO | 2--
Msrc/loaders/xbin.c | 7+++++++
2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/TODO b/TODO @@ -3,8 +3,6 @@ - Parse ANSI in two pass, like we do for Tundra, to avoid storing temporary data and save memory? - Use OpenBSD style(9) for function prototypes and declarations? -- Be more resilient with corrupt files, especially ADF / IDF / XBIN files - with malformed headers - Fix rendering bugs in the PabloDraw 24-bit ANSI sequences handling - Fuzz with AFL, especially for non ANSI formats - Allow enabling DOS aspect ratio + retina at the same time diff --git a/src/loaders/xbin.c b/src/loaders/xbin.c @@ -20,6 +20,8 @@ #include "fonts.h" #include "output.h" +#define XBIN_HEADER_LENGTH 11 /* 4 + 1 + 2 + 2 + 1 + 1 */ + int ansilove_xbin(struct ansilove_ctx *ctx, struct ansilove_options *options) { @@ -30,6 +32,11 @@ ansilove_xbin(struct ansilove_ctx *ctx, struct ansilove_options *options) return -1; } + if (ctx->length < XBIN_HEADER_LENGTH) { + ctx->error = ANSILOVE_FORMAT_ERROR; + return -1; + } + const uint8_t *font_data; uint8_t *font_data_xbin = NULL;