libansilove

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

commit a29249a4ffe3a1b2a801a1d4ceeea6dc93e6e598
parent a5928d670366448eaed5cda13e7fed50b55ba864
Author: Frederic Cambus <fred@statdns.com>
Date:   Wed, 21 Oct 2020 19:09:49 +0200

Add range integrity checks for columns value in relevant loaders.

Diffstat:
Msrc/loaders/ansi.c | 5+++++
Msrc/loaders/binary.c | 5+++++
Msrc/loaders/icedraw.c | 5+++++
Msrc/loaders/pcboard.c | 5+++++
Msrc/loaders/tundra.c | 5+++++
Msrc/loaders/xbin.c | 5+++++
6 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/src/loaders/ansi.c b/src/loaders/ansi.c @@ -105,6 +105,11 @@ ansilove_ansi(struct ansilove_ctx *ctx, struct ansilove_options *options) int16_t columns = options->columns; + if (columns < 1 || columns > 4096) { + ctx->error = ANSILOVE_RANGE_ERROR; + return -1; + } + bool ced = false; bool workbench = false; diff --git a/src/loaders/binary.c b/src/loaders/binary.c @@ -56,6 +56,11 @@ ansilove_binary(struct ansilove_ctx *ctx, struct ansilove_options *options) /* Default to 160 columns if columns option wasn't set */ options->columns = options->columns ? options->columns : 160; + if (options->columns < 1 || options->columns > 4096) { + ctx->error = ANSILOVE_RANGE_ERROR; + return -1; + } + width = options->columns * options->bits; height = ctx->length / 2 / options->columns * fontData.height; diff --git a/src/loaders/icedraw.c b/src/loaders/icedraw.c @@ -55,6 +55,11 @@ ansilove_icedraw(struct ansilove_ctx *ctx, struct ansilove_options *options) /* Get number of columns, 16-bit endian unsigned short */ uint32_t x2 = (ctx->buffer[9] << 8) + ctx->buffer[8] + 1; + if (x2 < 1 || x2 > 4096) { + ctx->error = ANSILOVE_RANGE_ERROR; + return -1; + } + /* process IDF */ /* dynamically allocated memory buffer for IDF data */ idf_buffer = malloc(2); diff --git a/src/loaders/pcboard.c b/src/loaders/pcboard.c @@ -69,6 +69,11 @@ ansilove_pcboard(struct ansilove_ctx *ctx, struct ansilove_options *options) options->columns = options->columns ? options->columns : 80; uint16_t columns = options->columns; + if (columns < 1 || columns > 4096) { + ctx->error = ANSILOVE_RANGE_ERROR; + return -1; + } + /* font selection */ memset(&fontData, 0, sizeof(struct fontStruct)); select_font(&fontData, options->font); diff --git a/src/loaders/tundra.c b/src/loaders/tundra.c @@ -55,6 +55,11 @@ ansilove_tundra(struct ansilove_ctx *ctx, struct ansilove_options *options) options->columns = options->columns ? options->columns : 80; int16_t columns = options->columns; + if (columns < 1 || columns > 4096) { + ctx->error = ANSILOVE_RANGE_ERROR; + return -1; + } + /* font selection */ memset(&fontData, 0, sizeof(struct fontStruct)); select_font(&fontData, options->font); diff --git a/src/loaders/xbin.c b/src/loaders/xbin.c @@ -67,6 +67,11 @@ ansilove_xbin(struct ansilove_ctx *ctx, struct ansilove_options *options) return -1; } + if (xbin_width < 1 || xbin_width > 4096) { + ctx->error = ANSILOVE_RANGE_ERROR; + return -1; + } + width = 8 * xbin_width; height = xbin_fontsize * xbin_height;