]> gitweb.michael.orlitzky.com - libsvgtiny.git/commitdiff
Update test dir to add fuzzer configuration
authorVincent Sanders <vince@kyllikki.org>
Fri, 21 Jun 2024 15:26:07 +0000 (16:26 +0100)
committerVincent Sanders <vince@kyllikki.org>
Thu, 25 Jul 2024 20:48:08 +0000 (21:48 +0100)
test/Makefile
test/afl-svg.dict
test/runtest.sh
test/svg2mvg.c [moved from test/decode_svg.c with 100% similarity]
test/svgparse.c [new file with mode: 0644]

index 49fb64d136b51607dc14b32088842a4c7efe9e57..78c683a8f0a706d85bc0746b7c4c931d4b033994 100644 (file)
@@ -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
index 2f6c05948cca5a5fc293533c298e7ffa5e5962d8..c6208a4ec54e51ba5b6961dbebd707e3cf5bce2e 100644 (file)
-#
-# AFL dictionary for SVG
-# ----------------------
-#
-# Several basic syntax elements and attributes, modeled on AFL XML dictionary
-#
-# Michal Zalewski <lcamtuf@google.com>
-# Vincent Sanders <vince@netsurf-browser.org>
-#
+# 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="<a"
-tag_open_close="<a />"
-tag_close="</a>"
-tag_altGlyph="<altGlyph"
-tag_altGlyphDef="<altGlyphDef"
-tag_altGlyphItem="<altGlyphItem"
-tag_animate="<animate"
-tag_animateColor="<animateColor"
-tag_animateMotion="<animateMotion"
-tag_animateTransform="<animateTransform"
-tag_circle="<circle"
-tag_clipPath="<clipPath"
-tag_close_clipPath="</clipPath>"
-tag_color_profile="<color-profile"
-tag_cursor="<cursor"
-tag_defs="<defs"
-tag_desc="<desc"
-tag_ellipse="<ellipse"
-tag_feBlend="<feBlend"
-tag_feColorMatrix="<feColorMatrix"
-tag_feComponentTransfer="<feComponentTransfer"
-tag_feComposite="<feComposite"
-tag_feConvolveMatrix="<feConvolveMatrix"
-tag_feDiffuseLighting="<feDiffuseLighting"
-tag_feDisplacementMap="<feDisplacementMap"
-tag_feDistantLight="<feDistantLight"
-tag_feFlood="<feFlood"
-tag_feFuncA="<feFuncA"
-tag_feFuncB="<feFuncB"
-tag_feFuncG="<feFuncG"
-tag_feFuncR="<feFuncR"
-tag_feGaussianBlur="<feGaussianBlur"
-tag_feImage="<feImage"
-tag_feMerge="<feMerge"
-tag_feMergeNode="<feMergeNode"
-tag_feMorphology="<feMorphology"
-tag_feOffset="<feOffset"
-tag_fePointLight="<fePointLight"
-tag_feSpecularLighting="<feSpecularLighting"
-tag_feSpotLight="<feSpotLight"
-tag_feTile="<feTile"
-tag_feTurbulence="<feTurbulence"
-tag_filter="<filter"
-tag_font="<font"
-tag_font_face="<font-face"
-tag_font_face_format="<font-face-format"
-tag_font_face_name="<font-face-name"
-tag_font_face_src="<font-face-src"
-tag_font_face_uri="<font-face-uri"
-tag_foreignObject="<foreignObject"
-tag_g="<g"
-tag_close_g="</g>"
-tag_glyph="<glyph"
-tag_glyphRef="<glyphRef"
-tag_hkern="<hkern"
-tag_image="<image"
-tag_line="<line"
-tag_linearGradient="<linearGradient"
-tag_marker="<marker"
-tag_mask="<mask"
-tag_metadata="<metadata"
-tag_missing_glyph="<missing-glyph"
-tag_mpath="<mpath"
-tag_path="<path"
-tag_pattern="<pattern"
-tag_polygon="<polygon"
-tag_polyline="<polyline"
-tag_radialGradient="<radialGradient"
-tag_rect="<rect"
-tag_script="<script"
-tag_set="<set"
-tag_stop="<stop"
-tag_style="<style"
-tag_svg="<svg"
-tag_switch="<switch"
-tag_symbol="<symbol"
-tag_text="<text"
-tag_textPath="<textPath"
-tag_title="<title"
-tag_tref="<tref"
-tag_tspan="<tspan"
-tag_use="<use"
-tag_view="<view"
-tag_vkern="<vkern"
+"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+"standalone="
+"version="
+"encoding="
+"<?xml"
+"?>"
+"/>"
+"<![CDATA["
 
-attrribute_id=" id"
-attrribute_transform=" transform"
-attrribute_target=" target"
-attrribute_d=" d"
-attrribute_style=" style"
-attrribute_width=" width"
-attrribute_height=" height"
-attrribute_x=" x"
-attrribute_y=" y"
-attrribute_anchor=" text-anchor"
+# tags
+"<svg"
+"xmlns=\"http://www.w3.org/2000/svg\""
+"<a"
+"<animate"
+"<animateMotion"
+"<animateTransform"
+"<circle"
+"<clipPath"
+"<color-profile"
+"<defs"
+"<desc"
+"<discard"
+"<ellipse"
+"<feBlend"
+"<feColorMatrix"
+"<feComponentTransfer"
+"<feComposite"
+"<feConvolveMatrix"
+"<feDiffuseLighting"
+"<feDisplacementMap"
+"<feDistantLight"
+"<feDropShadow"
+"<feFlood"
+"<feFuncA"
+"<feFuncB"
+"<feFuncG"
+"<feFuncR"
+"<feGaussianBlur"
+"<feImage"
+"<feMerge"
+"<feMergeNode"
+"<feMorphology"
+"<feOffset"
+"<fePointLight"
+"<feSpecularLighting"
+"<feSpotLight"
+"<feTile"
+"<feTurbulence"
+"<filter"
+"<foreignObject"
+"<g"
+"<hatch"
+"<hatchpath"
+"<image"
+"<line"
+"<linearGradient"
+"<marker"
+"<mask"
+"<mesh"
+"<meshgradient"
+"<meshpatch"
+"<meshrow"
+"<metadata"
+"<mpath"
+"<path"
+"<pattern"
+"<polygon"
+"<polyline"
+"<radialGradient"
+"<rect"
+"<rect"
+"<script"
+"<script>"
+"<set"
+"<solidcolor"
+"<stop"
+"<style"
+"<svg"
+"<switch"
+"<symbol"
+"<text"
+"<textArea"
+"<textPath"
+"<title"
+"<title>"
+"<tspan"
+"<unknown"
+"<use"
+"<view"
 
-attr_encoding=" encoding=\"1\""
-attr_generic=" a=\"1\""
-attr_href=" href=\"1\""
-attr_standalone=" standalone=\"no\""
-attr_version=" version=\"1\""
-attr_xml_base=" xml:base=\"1\""
-attr_xml_id=" xml:id=\"1\""
-attr_xml_lang=" xml:lang=\"1\""
-attr_xml_space=" xml:space=\"1\""
-attr_xmlns=" xmlns=\"1\""
 
-entity_builtin="&lt;"
-entity_decimal="&#1;"
-entity_external="&a;"
-entity_hex="&#x1;"
-
-string_any="ANY"
-string_brackets="[]"
-string_cdata="CDATA"
-string_col_fallback=":fallback"
-string_col_generic=":a"
-string_col_include=":include"
-string_dashes="--"
-string_empty="EMPTY"
-string_empty_dblquotes="\"\""
-string_empty_quotes="''"
-string_entities="ENTITIES"
-string_entity="ENTITY"
-string_fixed="#FIXED"
-string_id="ID"
-string_idref="IDREF"
-string_idrefs="IDREFS"
-string_implied="#IMPLIED"
-string_nmtoken="NMTOKEN"
-string_nmtokens="NMTOKENS"
-string_notation="NOTATION"
-string_parentheses="()"
-string_pcdata="#PCDATA"
-string_percent="%a"
-string_public="PUBLIC"
-string_required="#REQUIRED"
-string_schema=":schema"
-string_system="SYSTEM"
-string_ucs4="UCS-4"
-string_utf16="UTF-16"
-string_utf8="UTF-8"
-string_xmlns="xmlns:"
-
-tag_attlist="<!ATTLIST"
-tag_cdata="<![CDATA["
-tag_doctype="<!DOCTYPE"
-tag_element="<!ELEMENT"
-tag_entity="<!ENTITY"
-tag_ignore="<![IGNORE["
-tag_include="<![INCLUDE["
-tag_notation="<!NOTATION"
-tag_open_exclamation="<!"
-tag_open_q="<?"
-tag_sq2_close="]]>"
-tag_xml_q="<?xml?>"
+# attributes
+"alignment-baseline"
+"baseline-shift"
+"class"
+"color"
+"cursor"
+"cx"
+"cy"
+"direction"
+"display"
+"dominant-baseline"
+"editable"
+"fill"
+"fill-opacity"
+"font-family"
+"font-size"
+"font-size-adjust"
+"font-stretch"
+"font-style"
+"font-variant"
+"font-weight"
+"glyph-orientation-horizontal"
+"glyph-orientation-vertical"
+"gradientUnits"
+"height"
+"kerning""
+"letter-spacing"
+"offset"
+"overflow"
+"patternContentUnits"
+"pointer-events"
+"points"
+"rotate"
+"rx"
+"ry"
+"spreadMethod"
+"stop-color"
+"stop-opacity"
+"stroke"
+"stroke-dasharray"
+"stroke-linecap"
+"stroke-linejoin"
+"stroke-opacity"
+"stroke-width"
+"style"
+"text-anchor"
+"text-decoration"
+"textlength"
+"transform"
+"unicode-bidi"
+"visibility"
+"width"
+"word-spacing"
+"writing-mode"
+"x1"
+"x2"
+"y1"
+"y2"
 
+# attributes' values
+"bounding-Box"
+"repeat"
+"display"
+"transparent"
+"orange"
+"round"
+"butt"
+"userSpaceOnUse"
+"objectBoundingBox"
+"square"
+"miter"
+"bevel"
+"translate("
+"rotate("
+"matrix("
+"skewX("
+"skewY("
index 35dc17f97cecc0ba259d65e1ec60b62f80998173..4bc39ef2c44c7882cc86d43d6c152cc5dcb33aeb 100755 (executable)
@@ -10,6 +10,7 @@
 TEST_PATH=$1
 TEST_OUT=${TEST_PATH}/mvg
 TEST_LOG=${TEST_PATH}/test.log
+TEST_PROGRAM=${TEST_PATH}/test_svg2mvg
 
 mkdir -p ${TEST_OUT}
 
@@ -30,7 +31,7 @@ svgdecode()
     OUTNAME=${TEST_OUT}/${LEAFNAME}.mvg # name of the generated output file
 
     echo "SVG:${1}" >> ${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
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 (file)
index 0000000..67a2100
--- /dev/null
@@ -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 <james@semichrome.net>
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdlib.h>
+#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;
+}