From: Vincent Sanders Date: Fri, 21 Jun 2024 15:26:07 +0000 (+0100) Subject: Update test dir to add fuzzer configuration X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=4eaab432de5adff971b10749d947deda715ca70c;p=libsvgtiny.git Update test dir to add fuzzer configuration --- diff --git a/test/Makefile b/test/Makefile index 49fb64d..78c683a 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,4 +1,9 @@ # Tests -DIR_TEST_ITEMS := decode_svg:decode_svg.c +DIR_TEST_ITEMS := svg2mvg:svg2mvg.c + +# Fuzzer +DIR_FUZZER_ITEM := svgparse:svgparse.c +DIR_FUZZER_INPUT := ns-afl-svg +DIR_FUZZER_DICT := afl-svg.dict include $(NSBUILD)/Makefile.subdir diff --git a/test/afl-svg.dict b/test/afl-svg.dict index 2f6c059..c6208a4 100644 --- a/test/afl-svg.dict +++ b/test/afl-svg.dict @@ -1,170 +1,172 @@ -# -# AFL dictionary for SVG -# ---------------------- -# -# Several basic syntax elements and attributes, modeled on AFL XML dictionary -# -# Michal Zalewski -# Vincent Sanders -# +# Keywords taken from +# - https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Introduction +# - https://css-tricks.com/svg-properties-and-css/ -# SVG element reference from MDN -# https://developer.mozilla.org/en-US/docs/Web/SVG/Element -# -tag_a="" +"standalone=" +"version=" +"encoding=" +"" +"/>" +"" +"" +"> ${TEST_LOG} - ${TEST_PATH}/test_decode_svg ${1} 1.0 ${OUTNAME} 2>> ${TEST_LOG} + ${TEST_PROGRAM} ${1} 1.0 ${OUTNAME} 2>> ${TEST_LOG} ECODE=$? if [ "${ECODE}" -gt 0 ];then diff --git a/test/decode_svg.c b/test/svg2mvg.c similarity index 100% rename from test/decode_svg.c rename to test/svg2mvg.c diff --git a/test/svgparse.c b/test/svgparse.c new file mode 100644 index 0000000..67a2100 --- /dev/null +++ b/test/svgparse.c @@ -0,0 +1,97 @@ +/* + * This file is part of Libsvgtiny + * Licensed under the MIT License, + * http://opensource.org/licenses/mit-license.php + * Copyright 2008 James Bursa + */ + +#include +#include +#include +#include +#include +#include "svgtiny.h" + +/* trivial test program that creates a svg diagram and parses it */ +int main(int argc, char *argv[]) +{ + FILE *fd; + struct stat sb; + char *buffer; + size_t size; + size_t n; + struct svgtiny_diagram *diagram; + svgtiny_code code; + + if (argc != 2) { + fprintf(stderr, "Usage: %s FILE\n", argv[0]); + return 1; + } + + /* load file into memory buffer */ + fd = fopen(argv[1], "rb"); + if (!fd) { + perror(argv[1]); + return 1; + } + + if (stat(argv[1], &sb)) { + perror(argv[1]); + return 1; + } + size = sb.st_size; + + buffer = malloc(size); + if (!buffer) { + fprintf(stderr, "Unable to allocate %lld bytes\n", + (long long) size); + return 1; + } + + n = fread(buffer, 1, size, fd); + if (n != size) { + perror(argv[1]); + return 1; + } + + fclose(fd); + + /* create svgtiny object */ + diagram = svgtiny_create(); + if (!diagram) { + fprintf(stderr, "svgtiny_create failed\n"); + return 1; + } + + /* parse */ + code = svgtiny_parse(diagram, buffer, size, argv[1], 1000, 1000); + if (code != svgtiny_OK) { + fprintf(stderr, "svgtiny_parse failed: "); + switch (code) { + case svgtiny_OUT_OF_MEMORY: + fprintf(stderr, "svgtiny_OUT_OF_MEMORY"); + break; + case svgtiny_LIBDOM_ERROR: + fprintf(stderr, "svgtiny_LIBDOM_ERROR"); + break; + case svgtiny_NOT_SVG: + fprintf(stderr, "svgtiny_NOT_SVG"); + break; + case svgtiny_SVG_ERROR: + fprintf(stderr, "svgtiny_SVG_ERROR: line %i: %s", + diagram->error_line, + diagram->error_message); + break; + default: + fprintf(stderr, "unknown svgtiny_code %i", code); + break; + } + fprintf(stderr, "\n"); + } + + free(buffer); + + svgtiny_free(diagram); + + return 0; +}