Hello community, here is the log from the commit of package libansilove for openSUSE:Factory checked in at 2020-10-23 12:22:30 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/libansilove (Old) and /work/SRC/openSUSE:Factory/.libansilove.new.3463 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "libansilove" Fri Oct 23 12:22:30 2020 rev:12 rq:843536 version:1.2.7 Changes: -------- --- /work/SRC/openSUSE:Factory/libansilove/libansilove.changes 2020-10-05 19:36:38.789406601 +0200 +++ /work/SRC/openSUSE:Factory/.libansilove.new.3463/libansilove.changes 2020-10-23 12:23:59.944762079 +0200 @@ -1,0 +2,18 @@ +Thu Oct 22 19:11:56 UTC 2020 - Martin Hauke <[email protected]> + +- Update to version 1.2.7 + - Error out early with ANSILOVE_FORMAT_ERROR in case ctx->length + is 0. + - Initialize ansi_buffer and pcboard_buffer to NULL. + - Refactor the IceDraw loader to use a state machine. + - Check strndup() return value and error out on failed allocations + - Add some file format integrity checks in the IceDraw loader. + - Add range integrity checks for scale_factor values in the + output() function. + - Return error code directly if ctx->length is 0 in the ANSI and + PCBoard loaders. + - Add range integrity checks for columns value in relevant loaders + - Add range integrity checks for bits value in relevant loaders + - Add additional file format integrity check in the XBin loader + +------------------------------------------------------------------- Old: ---- libansilove-1.2.6.tar.gz New: ---- libansilove-1.2.7.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ libansilove.spec ++++++ --- /var/tmp/diff_new_pack.hGdF0X/_old 2020-10-23 12:24:00.736764350 +0200 +++ /var/tmp/diff_new_pack.hGdF0X/_new 2020-10-23 12:24:00.740764361 +0200 @@ -20,7 +20,7 @@ %global sover 1 %global libname %{name}%{sover} Name: libansilove -Version: 1.2.6 +Version: 1.2.7 Release: 0 Summary: Library for converting ANSI, ASCII, and other formats to PNG License: BSD-2-Clause ++++++ libansilove-1.2.6.tar.gz -> libansilove-1.2.7.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/.travis.yml new/libansilove-1.2.7/.travis.yml --- old/libansilove-1.2.6/.travis.yml 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/.travis.yml 2020-10-21 23:45:38.000000000 +0200 @@ -31,7 +31,7 @@ coverity_scan: project: name: "ansilove/libansilove" - version: 1.2.6 + version: 1.2.7 description: "Library for converting ANSI, ASCII, and other formats to PNG" notification_email: [email protected] build_command_prepend: cmake . diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/CMakeLists.txt new/libansilove-1.2.7/CMakeLists.txt --- old/libansilove-1.2.6/CMakeLists.txt 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/CMakeLists.txt 2020-10-21 23:45:38.000000000 +0200 @@ -2,7 +2,7 @@ set(LIB_VERSION_MAJOR 1) set(LIB_VERSION_MINOR 2) -set(LIB_VERSION_PATCH 6) +set(LIB_VERSION_PATCH 7) set(LIB_VERSION_STRING ${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_PATCH}) project (ansilove C) @@ -22,6 +22,7 @@ find_library(GD_LIBRARIES NAMES gd REQUIRED) include_directories(${GD_INCLUDE_DIRS}) +set(CMAKE_BUILD_TYPE Release) set(SRC src/clean.c src/drawchar.c src/fonts.c src/error.c src/loadfile.c src/init.c src/output.c src/savefile.c) set(LOADERS src/loaders/ansi.c src/loaders/artworx.c src/loaders/binary.c src/loaders/icedraw.c src/loaders/pcboard.c src/loaders/tundra.c src/loaders/xbin.c) @@ -33,7 +34,7 @@ set (SRC ${SRC} compat/reallocarray.c) endif() -add_definitions(-D_GNU_SOURCE -Wall -Wextra -std=c99 -pedantic) +add_definitions(-D_GNU_SOURCE -D_FORTIFY_SOURCE=2 -Wall -Wextra -std=c99 -pedantic) add_library(ansilove SHARED ${SRC} ${LOADERS}) target_link_libraries(ansilove ${GD_LIBRARIES} m) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/ChangeLog new/libansilove-1.2.7/ChangeLog --- old/libansilove-1.2.6/ChangeLog 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/ChangeLog 2020-10-21 23:45:38.000000000 +0200 @@ -1,3 +1,21 @@ +libansilove 1.2.7 (2020-10-21) + +- Error out early with ANSILOVE_FORMAT_ERROR in case ctx->length is 0 +- Enable FORTIFY_SOURCE level 2 +- Set CMAKE_BUILD_TYPE to "Release" in CMakeLists.txt +- Move variables declaration to the top of each loader function +- Initialize ansi_buffer and pcboard_buffer to NULL +- Refactor the IceDraw loader to use a state machine +- Check strndup() return value and error out on failed allocations +- Add some file format integrity checks in the IceDraw loader +- Add range integrity checks for scale_factor values in the output() function +- Return error code directly if ctx->length is 0 in the ANSI and PCBoard loaders +- Add range integrity checks for columns value in relevant loaders +- Add range integrity checks for bits value in relevant loaders +- Add additional file format integrity check in the XBin loader + + + libansilove 1.2.6 (2020-09-30) - Introduce canvas' width/height variables and refactor canvas creation diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/include/ansilove.h new/libansilove-1.2.7/include/ansilove.h --- old/libansilove-1.2.6/include/ansilove.h 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/include/ansilove.h 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * ansilove.h - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus @@ -20,11 +20,11 @@ #define ANSILOVE_EXTERN __attribute__((visibility("default"))) /* Version number */ -#define ANSILOVE_VERSION "1.2.6" +#define ANSILOVE_VERSION "1.2.7" #define ANSILOVE_VERSION_MAJOR 1 #define ANSILOVE_VERSION_MINOR 2 -#define ANSILOVE_VERSION_PATCH 6 +#define ANSILOVE_VERSION_PATCH 7 /* Error codes */ #define ANSILOVE_INVALID_PARAM 1 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/src/clean.c new/libansilove-1.2.7/src/clean.c --- old/libansilove-1.2.6/src/clean.c 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/src/clean.c 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * clean.c - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/src/config.h new/libansilove-1.2.7/src/config.h --- old/libansilove-1.2.6/src/config.h 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/src/config.h 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * config.h - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/src/drawchar.c new/libansilove-1.2.7/src/drawchar.c --- old/libansilove-1.2.6/src/drawchar.c 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/src/drawchar.c 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * drawchar.c - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/src/drawchar.h new/libansilove-1.2.7/src/drawchar.h --- old/libansilove-1.2.6/src/drawchar.h 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/src/drawchar.h 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * drawchar.h - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/src/error.c new/libansilove-1.2.7/src/error.c --- old/libansilove-1.2.6/src/error.c 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/src/error.c 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * error.c - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/src/fonts.c new/libansilove-1.2.7/src/fonts.c --- old/libansilove-1.2.6/src/fonts.c 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/src/fonts.c 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * fonts.c - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/src/fonts.h new/libansilove-1.2.7/src/fonts.h --- old/libansilove-1.2.6/src/fonts.h 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/src/fonts.h 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * fonts.h - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/src/init.c new/libansilove-1.2.7/src/init.c --- old/libansilove-1.2.6/src/init.c 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/src/init.c 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * init.c - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/src/loaders/ansi.c new/libansilove-1.2.7/src/loaders/ansi.c --- old/libansilove-1.2.6/src/loaders/ansi.c 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/src/loaders/ansi.c 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * ansi.c - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus @@ -50,42 +50,8 @@ int ansilove_ansi(struct ansilove_ctx *ctx, struct ansilove_options *options) { - if (ctx == NULL || options == NULL) { - if (ctx) - ctx->error = ANSILOVE_INVALID_PARAM; - - return -1; - } - - /* ladies and gentlemen, it's type declaration time */ - struct fontStruct fontData; - - /* Default to 80 columns if columns option wasn't set */ - options->columns = options->columns ? options->columns : 80; - - int16_t columns = options->columns; - - bool ced = false; - bool workbench = false; - const char *errstr; - /* font selection */ - memset(&fontData, 0, sizeof(struct fontStruct)); - select_font(&fontData, options->font); - - switch (options->mode) { - case ANSILOVE_MODE_CED: - ced = true; - break; - case ANSILOVE_MODE_WORKBENCH: - workbench = true; - break; - } - - /* libgd image pointers */ - gdImagePtr canvas; - /* ANSi processing loops */ size_t loop = 0, ansi_sequence_loop; @@ -97,6 +63,7 @@ /* default color values */ uint32_t background = 0, foreground = 7; uint32_t background24 = 0, foreground24 = 0; + uint32_t colors[16]; /* text attributes */ bool bold = false, blink = false, invert = false; @@ -113,10 +80,57 @@ /* ANSi buffer structure array definition */ size_t structIndex = 0; - struct ansiChar *ptr, *ansi_buffer; + struct ansiChar *ptr, *ansi_buffer = NULL; + struct fontStruct fontData; size_t ansi_buffer_size = ANSI_BUFFER_SIZE; + /* libgd image pointers */ + gdImagePtr canvas; + + if (ctx == NULL || options == NULL) { + if (ctx) + ctx->error = ANSILOVE_INVALID_PARAM; + + return -1; + } + + if (!ctx->length) { + ctx->error = ANSILOVE_FORMAT_ERROR; + return -1; + } + + if (options->bits != 8 && options->bits !=9) { + ctx->error = ANSILOVE_RANGE_ERROR; + return -1; + } + + /* Default to 80 columns if columns option wasn't set */ + options->columns = options->columns ? options->columns : 80; + + int16_t columns = options->columns; + + if (columns < 1 || columns > 4096) { + ctx->error = ANSILOVE_RANGE_ERROR; + return -1; + } + + bool ced = false; + bool workbench = false; + + /* font selection */ + memset(&fontData, 0, sizeof(struct fontStruct)); + select_font(&fontData, options->font); + + switch (options->mode) { + case ANSILOVE_MODE_CED: + ced = true; + break; + case ANSILOVE_MODE_WORKBENCH: + workbench = true; + break; + } + /* ANSi buffer dynamic memory allocation */ ansi_buffer = malloc(ansi_buffer_size * sizeof(struct ansiChar)); @@ -208,6 +222,10 @@ seq_line = 1; seq_column = 1; seqGrab = strndup((char *)cursor, ansi_sequence_loop); + if (!seqGrab) { + ctx->error = ANSILOVE_MEMORY_ERROR; + goto error; + } if (!strncmp(seqGrab, ";", 1)) { seq_line = 1; @@ -238,6 +256,10 @@ if (ansi_sequence_character == 'A') { /* create substring from the sequence's content */ seqGrab = strndup((char *)cursor, ansi_sequence_loop); + if (!seqGrab) { + ctx->error = ANSILOVE_MEMORY_ERROR; + goto error; + } /* now get escape sequence's position value */ uint32_t seq_line = strtonum(seqGrab, 0, UINT32_MAX, &errstr); @@ -256,6 +278,10 @@ if (ansi_sequence_character == 'B') { /* create substring from the sequence's content */ seqGrab = strndup((char *)cursor, ansi_sequence_loop); + if (!seqGrab) { + ctx->error = ANSILOVE_MEMORY_ERROR; + goto error; + } /* now get escape sequence's position value */ uint32_t seq_line = strtonum(seqGrab, 0, UINT32_MAX, &errstr); @@ -271,6 +297,10 @@ if (ansi_sequence_character == 'C') { /* create substring from the sequence's content */ seqGrab = strndup((char *)cursor, ansi_sequence_loop); + if (!seqGrab) { + ctx->error = ANSILOVE_MEMORY_ERROR; + goto error; + } /* now get escape sequence's position value */ uint32_t seq_column = strtonum(seqGrab, 0, UINT32_MAX, &errstr); @@ -289,6 +319,10 @@ if (ansi_sequence_character == 'D') { /* create substring from the sequence's content */ seqGrab = strndup((char *)cursor, ansi_sequence_loop); + if (!seqGrab) { + ctx->error = ANSILOVE_MEMORY_ERROR; + goto error; + } /* now get escape sequence's content length */ uint32_t seq_column = strtonum(seqGrab, 0, UINT32_MAX, &errstr); @@ -325,6 +359,10 @@ if (ansi_sequence_character == 'J') { /* create substring from the sequence's content */ seqGrab = strndup((char *)cursor, ansi_sequence_loop); + if (!seqGrab) { + ctx->error = ANSILOVE_MEMORY_ERROR; + goto error; + } /* convert grab to an integer */ uint32_t eraseDisplayInt = strtonum(seqGrab, 0, UINT32_MAX, &errstr); @@ -348,6 +386,10 @@ if (ansi_sequence_character == 'm') { /* create substring from the sequence's content */ seqGrab = strndup((char *)cursor, ansi_sequence_loop); + if (!seqGrab) { + ctx->error = ANSILOVE_MEMORY_ERROR; + goto error; + } seqTok = strtok(seqGrab, ";"); while (seqTok) { @@ -433,6 +475,10 @@ /* create substring from the sequence's content */ seqGrab = strndup((char *)cursor, ansi_sequence_loop); + if (!seqGrab) { + ctx->error = ANSILOVE_MEMORY_ERROR; + goto error; + } seqTok = strtok(seqGrab, ";"); if (seqTok) { @@ -500,8 +546,6 @@ goto error; } - uint32_t colors[16]; - uint32_t ced_background = 0, ced_foreground = 0; if (ced) { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/src/loaders/artworx.c new/libansilove-1.2.7/src/loaders/artworx.c --- old/libansilove-1.2.6/src/loaders/artworx.c 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/src/loaders/artworx.c 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * artworx.c - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus @@ -26,6 +26,15 @@ int ansilove_artworx(struct ansilove_ctx *ctx, struct ansilove_options *options) { + uint8_t character, attribute, *cursor, state = STATE_CHARACTER; + uint32_t column = 0, row = 0; + uint32_t foreground, background; + uint32_t width, height; + size_t index, loop; + + /* libgd image pointers */ + gdImagePtr canvas; + if (ctx == NULL || options == NULL) { if (ctx) ctx->error = ANSILOVE_INVALID_PARAM; @@ -38,12 +47,7 @@ return -1; } - /* libgd image pointers */ - gdImagePtr canvas; - /* create ADF instance */ - - uint32_t width, height; width = 640; height = (ctx->length - ADF_HEADER_LENGTH) / 2 / 80 * 16; @@ -59,7 +63,6 @@ return -1; } - size_t index, loop; /* process ADF palette */ for (loop = 0; loop < 16; loop++) { @@ -71,9 +74,6 @@ } /* process ADF */ - uint8_t character, attribute, *cursor, state = STATE_CHARACTER; - uint32_t column = 0, row = 0; - uint32_t foreground, background; loop = ADF_HEADER_LENGTH; while (loop < ctx->length) { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/src/loaders/binary.c new/libansilove-1.2.7/src/loaders/binary.c --- old/libansilove-1.2.6/src/loaders/binary.c 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/src/loaders/binary.c 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * binary.c - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus @@ -26,6 +26,17 @@ int ansilove_binary(struct ansilove_ctx *ctx, struct ansilove_options *options) { + uint8_t character, attribute, *cursor, state = STATE_CHARACTER; + int32_t column = 0, row = 0; + uint32_t background, foreground; + uint32_t width, height; + uint32_t colors[16]; + size_t loop = 0; + struct fontStruct fontData; + + /* libgd image pointers */ + gdImagePtr canvas; + if (ctx == NULL || options == NULL) { if (ctx) ctx->error = ANSILOVE_INVALID_PARAM; @@ -33,19 +44,28 @@ return -1; } - struct fontStruct fontData; + if (!ctx->length) { + ctx->error = ANSILOVE_FORMAT_ERROR; + return -1; + } + + if (options->bits != 8 && options->bits !=9) { + ctx->error = ANSILOVE_RANGE_ERROR; + return -1; + } /* font selection */ memset(&fontData, 0, sizeof(struct fontStruct)); select_font(&fontData, options->font); - /* libgd image pointers */ - gdImagePtr canvas; - /* Default to 160 columns if columns option wasn't set */ options->columns = options->columns ? options->columns : 160; - uint32_t width, height; + 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; @@ -63,18 +83,11 @@ } /* allocate color palette */ - uint32_t colors[16]; - for (size_t i = 0; i < 16; i++) colors[i] = gdImageColorAllocate(canvas, vga_palette_red[i], vga_palette_green[i], vga_palette_blue[i]); /* process binary */ - uint8_t character, attribute, *cursor, state = STATE_CHARACTER; - uint32_t background, foreground; - size_t loop = 0; - int32_t column = 0, row = 0; - while (loop < ctx->length) { cursor = &ctx->buffer[loop]; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/src/loaders/icedraw.c new/libansilove-1.2.7/src/loaders/icedraw.c --- old/libansilove-1.2.6/src/loaders/icedraw.c 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/src/loaders/icedraw.c 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * icedraw.c - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus @@ -21,9 +21,25 @@ #define IDF_FONT_LENGTH 4096 #define IDF_PALETTE_LENGTH 48 +#define STATE_CHARACTER 0 +#define STATE_ATTRIBUTE 1 +#define STATE_RLE 2 + int ansilove_icedraw(struct ansilove_ctx *ctx, struct ansilove_options *options) { + size_t index, loop = IDF_HEADER_LENGTH; + uint8_t *ptr, *idf_buffer; + uint8_t *cursor, state = STATE_CHARACTER; + uint32_t width, height; + uint32_t column = 0, row = 0; + uint32_t character, attribute, foreground, background; + uint32_t colors[16]; + uint32_t idf_sequence_length, i = 0; + + /* libgd image pointers */ + gdImagePtr canvas; + if (ctx == NULL || options == NULL) { if (ctx) ctx->error = ANSILOVE_INVALID_PARAM; @@ -39,17 +55,13 @@ /* Get number of columns, 16-bit endian unsigned short */ uint32_t x2 = (ctx->buffer[9] << 8) + ctx->buffer[8] + 1; - /* libgd image pointers */ - gdImagePtr canvas; - - size_t index, loop = IDF_HEADER_LENGTH; - uint32_t colors[16]; + if (x2 < 1 || x2 > 4096) { + ctx->error = ANSILOVE_RANGE_ERROR; + return -1; + } /* process IDF */ - uint32_t idf_sequence_length, i = 0; - /* dynamically allocated memory buffer for IDF data */ - uint8_t *ptr, *idf_buffer; idf_buffer = malloc(2); if (idf_buffer == NULL) { @@ -58,9 +70,44 @@ } while (loop < ctx->length - IDF_FONT_LENGTH - IDF_PALETTE_LENGTH) { - /* RLE compressed data */ - if (ctx->buffer[loop] == 1) { - idf_sequence_length = ctx->buffer[loop+2]; + cursor = &ctx->buffer[loop]; + + switch (state) { + case STATE_CHARACTER: + if (*cursor == 1) { + state = STATE_RLE; + loop++; + } else { + ptr = realloc(idf_buffer, i + 2); + if (ptr == NULL) { + ctx->error = ANSILOVE_MEMORY_ERROR; + goto error; + } + + idf_buffer = ptr; + idf_buffer[i] = *cursor; + i++; + state = STATE_ATTRIBUTE; + } + + loop++; + break; + case STATE_ATTRIBUTE: + idf_buffer[i] = *cursor; + i++; + + state = STATE_CHARACTER; + + loop++; + break; + case STATE_RLE: + /* RLE compressed data */ + idf_sequence_length = *cursor; + + if (loop + 3 >= ctx->length) { + ctx->error = ANSILOVE_FORMAT_ERROR; + goto error; + } while (idf_sequence_length--) { @@ -73,30 +120,16 @@ idf_buffer = ptr; - idf_buffer[i] = ctx->buffer[loop + 4]; - idf_buffer[i+1] = ctx->buffer[loop + 5]; + idf_buffer[i] = ctx->buffer[loop +2]; + idf_buffer[i+1] = ctx->buffer[loop + 3]; i += 2; } - loop += 4; - } else { - /* reallocate IDF buffer memory */ - ptr = realloc(idf_buffer, i + 2); - if (ptr == NULL) { - ctx->error = ANSILOVE_MEMORY_ERROR; - goto error; - } - - idf_buffer = ptr; - /* normal character */ - idf_buffer[i] = ctx->buffer[loop]; - idf_buffer[i+1] = ctx->buffer[loop + 1]; - i += 2; + loop += 4; + state = STATE_CHARACTER; } - loop += 2; } - uint32_t width, height; width = x2 * 8; height = i / 2 / 80 * 16; @@ -124,9 +157,6 @@ } /* render IDF */ - uint32_t column = 0, row = 0; - uint32_t character, attribute, foreground, background; - for (loop = 0; loop < i; loop += 2) { if (column == x2) { column = 0; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/src/loaders/pcboard.c new/libansilove-1.2.7/src/loaders/pcboard.c --- old/libansilove-1.2.6/src/loaders/pcboard.c 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/src/loaders/pcboard.c 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * pcboard.c - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus @@ -40,6 +40,20 @@ int ansilove_pcboard(struct ansilove_ctx *ctx, struct ansilove_options *options) { + uint8_t *cursor, state = STATE_TEXT; + uint32_t background = '0', foreground = '7'; + uint32_t column = 0, row = 0, rowMax = 0; + uint32_t width, height; + uint32_t colors[16]; + size_t loop = 0, structIndex = 0; + struct fontStruct fontData; + + /* PCB buffer structure array definition */ + struct pcbChar *ptr, *pcboard_buffer = NULL; + + /* libgd image pointers */ + gdImagePtr canvas; + if (ctx == NULL || options == NULL) { if (ctx) ctx->error = ANSILOVE_INVALID_PARAM; @@ -47,26 +61,28 @@ return -1; } - struct fontStruct fontData; - size_t loop = 0, structIndex = 0; + if (!ctx->length) { + ctx->error = ANSILOVE_FORMAT_ERROR; + return -1; + } + + if (options->bits != 8 && options->bits !=9) { + ctx->error = ANSILOVE_RANGE_ERROR; + return -1; + } 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); - /* libgd image pointers */ - gdImagePtr canvas; - - uint8_t *cursor, state = STATE_TEXT; - uint32_t background = '0', foreground = '7'; - uint32_t column = 0, row = 0, rowMax = 0; - - /* PCB buffer structure array definition */ - struct pcbChar *ptr, *pcboard_buffer; - /* PCB buffer dynamic memory allocation */ pcboard_buffer = malloc(sizeof (struct pcbChar)); @@ -169,7 +185,6 @@ } rowMax++; - uint32_t width, height; width = columns * options->bits; height = rowMax * fontData.height; @@ -187,8 +202,6 @@ } /* allocate color palette */ - uint32_t colors[16]; - for (size_t i = 0; i < 16; i++) colors[i] = gdImageColorAllocate(canvas, ansi_palette_red[i], ansi_palette_green[i], ansi_palette_blue[i]); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/src/loaders/tundra.c new/libansilove-1.2.7/src/loaders/tundra.c --- old/libansilove-1.2.6/src/loaders/tundra.c 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/src/loaders/tundra.c 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * tundra.c - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus @@ -32,6 +32,16 @@ int ansilove_tundra(struct ansilove_ctx *ctx, struct ansilove_options *options) { + char tundra_version; + int32_t column = 0, row = 1; + uint32_t cursor, character, background = 0, foreground = 0; + uint32_t width, height; + size_t loop = TUNDRA_HEADER_LENGTH; + struct fontStruct fontData; + + /* libgd image pointers */ + gdImagePtr canvas; + if (ctx == NULL || options == NULL) { if (ctx) ctx->error = ANSILOVE_INVALID_PARAM; @@ -42,19 +52,23 @@ if (ctx->length < TUNDRA_HEADER_LENGTH) goto error; - struct fontStruct fontData; - char tundra_version; + if (options->bits != 8 && options->bits !=9) { + ctx->error = ANSILOVE_RANGE_ERROR; + return -1; + } 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); - /* libgd image pointers */ - gdImagePtr canvas; - /* extract tundra header */ tundra_version = ctx->buffer[0]; @@ -63,10 +77,6 @@ goto error; /* read tundra file a first time to find the image size */ - uint32_t cursor, character, background = 0, foreground = 0; - size_t loop = TUNDRA_HEADER_LENGTH; - int32_t column = 0, row = 1; - while (loop < ctx->length) { if (column == columns) { column = 0; @@ -113,7 +123,6 @@ loop++; } - uint32_t width, height; width = columns * options->bits; height = row * fontData.height; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/src/loaders/xbin.c new/libansilove-1.2.7/src/loaders/xbin.c --- old/libansilove-1.2.6/src/loaders/xbin.c 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/src/loaders/xbin.c 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * xbin.c - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus @@ -26,6 +26,16 @@ int ansilove_xbin(struct ansilove_ctx *ctx, struct ansilove_options *options) { + const uint8_t *font_data; + uint8_t *font_data_xbin = NULL; + uint32_t width, height; + uint32_t colors[16]; + uint32_t offset = XBIN_HEADER_LENGTH; + uint32_t column = 0, row = 0, foreground, background; + int32_t character, attribute; + + gdImagePtr canvas; + if (ctx == NULL || options == NULL) { if (ctx) ctx->error = ANSILOVE_INVALID_PARAM; @@ -38,9 +48,6 @@ return -1; } - const uint8_t *font_data; - uint8_t *font_data_xbin = NULL; - if (strncmp((char *)ctx->buffer, "XBIN\x1a", 5) != 0) { ctx->error = ANSILOVE_FORMAT_ERROR; return -1; @@ -60,9 +67,11 @@ return -1; } - gdImagePtr canvas; + if (xbin_width < 1 || xbin_width > 4096) { + ctx->error = ANSILOVE_RANGE_ERROR; + return -1; + } - uint32_t width, height; width = 8 * xbin_width; height = xbin_fontsize * xbin_height; @@ -78,9 +87,6 @@ return -1; } - uint32_t colors[16]; - uint32_t offset = XBIN_HEADER_LENGTH; - /* palette */ if ((xbin_flags & 1) == 1) { size_t index, loop; @@ -135,9 +141,6 @@ xbin_fontsize = 16; } - uint32_t column = 0, row = 0, foreground, background; - int32_t character, attribute; - /* read compressed xbin */ if ((xbin_flags & 4) == 4) { while (offset + 1 < ctx->length && row != xbin_height) { @@ -151,9 +154,15 @@ while (counter--) { /* none */ if (ctype == 0) { - character = ctx->buffer[offset]; - attribute = ctx->buffer[offset + 1]; - offset += 2; + if (offset + 1 < ctx->length) { + character = ctx->buffer[offset]; + attribute = ctx->buffer[offset + 1]; + offset += 2; + } else { + ctx->error = ANSILOVE_FORMAT_ERROR; + free(font_data_xbin); + return -1; + } } /* char */ else if (ctype == 0x40) { diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/src/loadfile.c new/libansilove-1.2.7/src/loadfile.c --- old/libansilove-1.2.6/src/loadfile.c 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/src/loadfile.c 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * loadfile.c - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/src/output.c new/libansilove-1.2.7/src/output.c --- old/libansilove-1.2.6/src/output.c 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/src/output.c 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * output.c - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus @@ -37,6 +37,11 @@ /* Handle resizing */ if (options->scale_factor) { + if (options->scale_factor < 2 || options->scale_factor > 8) { + ctx->error = ANSILOVE_RANGE_ERROR; + return -1; + } + uint32_t width, height; gdImagePtr retina; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/src/output.h new/libansilove-1.2.7/src/output.h --- old/libansilove-1.2.6/src/output.h 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/src/output.h 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * output.h - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/libansilove-1.2.6/src/savefile.c new/libansilove-1.2.7/src/savefile.c --- old/libansilove-1.2.6/src/savefile.c 2020-09-30 22:33:45.000000000 +0200 +++ new/libansilove-1.2.7/src/savefile.c 2020-10-21 23:45:38.000000000 +0200 @@ -1,6 +1,6 @@ /* * savefile.c - * libansilove 1.2.6 + * libansilove 1.2.7 * https://www.ansilove.org * * Copyright (c) 2011-2020 Stefan Vogt, Brian Cassidy, and Frederic Cambus
