feat(anatomy): V1-2.2 classify and clean drawings before upload
The sanitiser walk names removals that carried active or external content; clean_svg answers clean, cleanable or rejected, the cleaned text reading back with no removal. Committed cairo and ImageMagick exports; the owner's editor exports go under exports/owner.
This commit is contained in:
1 parent
64a43840ce
commit
cf37aa265a
11 files changed
+840
-5
No files matched your search
@@ -0,0 +1,24 @@
|
||||
# Vector-tool exports (V1-2.2, contract §9.2)
|
||||
|
||||
Real files written by drawing tools, read by `crates/core/tests/svg_clean.rs` through the
|
||||
core's cleaning (`anatomy/svg/clean.rs`). Each file name starts with the tool and its version.
|
||||
None is edited by hand.
|
||||
|
||||
| File | Tool | How | Expected |
|
||||
|---|---|---|---|
|
||||
| `cairo-1.18.4-pycairo-1.27.0-shapes.svg` | cairo 1.18.4 through pycairo 1.27.0 | `generate.sh`: curves, gradient, dash, clip, alpha, text as glyph paths | cleanable: its colours are written `rgb(20%, 40%, 70%)`, a function the allowlist takes out of presentation attributes (`stop@stop-color`, `path@stroke`, `path@fill`, `g@fill`), so the cleaned drawing keeps its shapes and loses its colours |
|
||||
| `cairo-1.18.4-pycairo-1.27.0-raster.svg` | same | `generate.sh`: an 8 × 8 image surface painted | refused, `svg_active_content` (an embedded raster `<image>`) |
|
||||
| `imagemagick-7.1.2-18-draw.svg` | ImageMagick 7.1.2-18 Q16 | `generate.sh`: `-draw` circle, rectangle, polyline | read with no removal |
|
||||
| `imagemagick-7.1.2-18-mvg.svg` | same | `generate.sh`: an MVG file (its style settings land as bare text between elements, which the reader drops) | read with no removal |
|
||||
|
||||
`bash generate.sh` rewrites them from the tools installed here (no network).
|
||||
|
||||
## Editor exports, supplied by the owner (`owner/`)
|
||||
|
||||
The editors an administrator actually uses (Inkscape, Illustrator, Figma, Affinity) are not
|
||||
installed on the development machine; the owner exports a small drawing from each and puts
|
||||
the files in `owner/`, named `<tool>-<version>-<what>.svg` (for example
|
||||
`inkscape-1.4.2-plain-svg.svg`, `illustrator-29.3-export-as.svg`). The suite reads every file
|
||||
there: each must be refused (with a closed reason) or cleaned into a drawing that reads back
|
||||
with no removal, and a file whose name contains `-active-` must be refused for active content.
|
||||
Until files arrive, that test runs on an empty folder and the report of V1-2.2 says so.
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="150" viewBox="0 0 200 150">
|
||||
<defs>
|
||||
<image id="source-15" x="0" y="0" width="8" height="8" xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAABmJLR0QA/wD/AP+gvaeTAAAAFElEQVQImWM8IynJgA0wYRUdtBIAzC8BDibnFZsAAAAASUVORK5CYII="/>
|
||||
</defs>
|
||||
<use xlink:href="#source-15" transform="matrix(1, 0, 0, 1, 10, 10)"/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 483 B |
+41
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="150" viewBox="0 0 200 150">
|
||||
<defs>
|
||||
<g>
|
||||
<g id="glyph-0-0">
|
||||
<path d="M 7.140625 -1.25 L 7.140625 -3.59375 L 5.203125 -3.59375 L 5.203125 -4.578125 L 8.3125 -4.578125 L 8.3125 -0.8125 C 7.851562 -0.488281 7.347656 -0.242188 6.796875 -0.078125 C 6.253906 0.0859375 5.671875 0.171875 5.046875 0.171875 C 3.671875 0.171875 2.597656 -0.226562 1.828125 -1.03125 C 1.054688 -1.832031 0.671875 -2.941406 0.671875 -4.359375 C 0.671875 -5.796875 1.054688 -6.910156 1.828125 -7.703125 C 2.597656 -8.503906 3.671875 -8.90625 5.046875 -8.90625 C 5.609375 -8.90625 6.144531 -8.832031 6.65625 -8.6875 C 7.175781 -8.550781 7.65625 -8.347656 8.09375 -8.078125 L 8.09375 -6.8125 C 7.65625 -7.1875 7.1875 -7.46875 6.6875 -7.65625 C 6.195312 -7.84375 5.679688 -7.9375 5.140625 -7.9375 C 4.066406 -7.9375 3.257812 -7.632812 2.71875 -7.03125 C 2.1875 -6.4375 1.921875 -5.546875 1.921875 -4.359375 C 1.921875 -3.179688 2.1875 -2.289062 2.71875 -1.6875 C 3.257812 -1.09375 4.066406 -0.796875 5.140625 -0.796875 C 5.554688 -0.796875 5.925781 -0.832031 6.25 -0.90625 C 6.582031 -0.976562 6.878906 -1.09375 7.140625 -1.25 Z M 7.140625 -1.25 "/>
|
||||
</g>
|
||||
<g id="glyph-0-1">
|
||||
<path d="M 4.109375 -3.296875 C 3.242188 -3.296875 2.640625 -3.195312 2.296875 -3 C 1.960938 -2.800781 1.796875 -2.460938 1.796875 -1.984375 C 1.796875 -1.597656 1.921875 -1.289062 2.171875 -1.0625 C 2.429688 -0.84375 2.773438 -0.734375 3.203125 -0.734375 C 3.804688 -0.734375 4.285156 -0.941406 4.640625 -1.359375 C 5.003906 -1.785156 5.1875 -2.351562 5.1875 -3.0625 L 5.1875 -3.296875 Z M 6.265625 -3.75 L 6.265625 0 L 5.1875 0 L 5.1875 -1 C 4.9375 -0.601562 4.628906 -0.304688 4.265625 -0.109375 C 3.898438 0.078125 3.453125 0.171875 2.921875 0.171875 C 2.242188 0.171875 1.707031 -0.015625 1.3125 -0.390625 C 0.914062 -0.773438 0.71875 -1.28125 0.71875 -1.90625 C 0.71875 -2.644531 0.960938 -3.203125 1.453125 -3.578125 C 1.953125 -3.953125 2.691406 -4.140625 3.671875 -4.140625 L 5.1875 -4.140625 L 5.1875 -4.25 C 5.1875 -4.75 5.019531 -5.132812 4.6875 -5.40625 C 4.363281 -5.675781 3.910156 -5.8125 3.328125 -5.8125 C 2.953125 -5.8125 2.582031 -5.765625 2.21875 -5.671875 C 1.863281 -5.578125 1.523438 -5.441406 1.203125 -5.265625 L 1.203125 -6.265625 C 1.597656 -6.421875 1.976562 -6.535156 2.34375 -6.609375 C 2.71875 -6.679688 3.082031 -6.71875 3.4375 -6.71875 C 4.382812 -6.71875 5.09375 -6.472656 5.5625 -5.984375 C 6.03125 -5.492188 6.265625 -4.75 6.265625 -3.75 Z M 6.265625 -3.75 "/>
|
||||
</g>
|
||||
<g id="glyph-0-2">
|
||||
<path d="M 4.9375 -5.5625 C 4.8125 -5.625 4.675781 -5.671875 4.53125 -5.703125 C 4.394531 -5.742188 4.238281 -5.765625 4.0625 -5.765625 C 3.457031 -5.765625 2.988281 -5.566406 2.65625 -5.171875 C 2.332031 -4.773438 2.171875 -4.203125 2.171875 -3.453125 L 2.171875 0 L 1.09375 0 L 1.09375 -6.5625 L 2.171875 -6.5625 L 2.171875 -5.546875 C 2.398438 -5.941406 2.695312 -6.234375 3.0625 -6.421875 C 3.425781 -6.617188 3.867188 -6.71875 4.390625 -6.71875 C 4.460938 -6.71875 4.539062 -6.710938 4.625 -6.703125 C 4.71875 -6.691406 4.816406 -6.675781 4.921875 -6.65625 Z M 4.9375 -5.5625 "/>
|
||||
</g>
|
||||
<g id="glyph-0-3">
|
||||
<path d="M 3.671875 -5.8125 C 3.097656 -5.8125 2.640625 -5.582031 2.296875 -5.125 C 1.960938 -4.675781 1.796875 -4.0625 1.796875 -3.28125 C 1.796875 -2.488281 1.960938 -1.867188 2.296875 -1.421875 C 2.628906 -0.972656 3.085938 -0.75 3.671875 -0.75 C 4.242188 -0.75 4.695312 -0.972656 5.03125 -1.421875 C 5.375 -1.878906 5.546875 -2.5 5.546875 -3.28125 C 5.546875 -4.050781 5.375 -4.664062 5.03125 -5.125 C 4.695312 -5.582031 4.242188 -5.8125 3.671875 -5.8125 Z M 3.671875 -6.71875 C 4.609375 -6.71875 5.34375 -6.410156 5.875 -5.796875 C 6.414062 -5.191406 6.6875 -4.351562 6.6875 -3.28125 C 6.6875 -2.207031 6.414062 -1.363281 5.875 -0.75 C 5.34375 -0.132812 4.609375 0.171875 3.671875 0.171875 C 2.734375 0.171875 1.992188 -0.132812 1.453125 -0.75 C 0.921875 -1.363281 0.65625 -2.207031 0.65625 -3.28125 C 0.65625 -4.351562 0.921875 -5.191406 1.453125 -5.796875 C 1.992188 -6.410156 2.734375 -6.71875 3.671875 -6.71875 Z M 3.671875 -6.71875 "/>
|
||||
</g>
|
||||
<g id="glyph-0-4">
|
||||
<path d="M 2.203125 -8.421875 L 2.203125 -6.5625 L 4.421875 -6.5625 L 4.421875 -5.71875 L 2.203125 -5.71875 L 2.203125 -2.15625 C 2.203125 -1.625 2.273438 -1.28125 2.421875 -1.125 C 2.566406 -0.976562 2.863281 -0.90625 3.3125 -0.90625 L 4.421875 -0.90625 L 4.421875 0 L 3.3125 0 C 2.476562 0 1.898438 -0.15625 1.578125 -0.46875 C 1.265625 -0.78125 1.109375 -1.34375 1.109375 -2.15625 L 1.109375 -5.71875 L 0.328125 -5.71875 L 0.328125 -6.5625 L 1.109375 -6.5625 L 1.109375 -8.421875 Z M 2.203125 -8.421875 "/>
|
||||
</g>
|
||||
</g>
|
||||
<linearGradient id="linear-pattern-0" gradientUnits="userSpaceOnUse" x1="0" y1="0" x2="200" y2="0">
|
||||
<stop offset="0" stop-color="rgb(60%, 30%, 20%)" stop-opacity="1"/>
|
||||
<stop offset="1" stop-color="rgb(90%, 80%, 60%)" stop-opacity="0.7"/>
|
||||
</linearGradient>
|
||||
<clipPath id="clip-0">
|
||||
<path clip-rule="nonzero" d="M 65 60 L 135 60 L 135 100 L 65 100 Z M 65 60 "/>
|
||||
</clipPath>
|
||||
</defs>
|
||||
<path fill-rule="nonzero" fill="url(#linear-pattern-0)" stroke-width="2" stroke-linecap="butt" stroke-linejoin="miter" stroke="rgb(20%, 20%, 20%)" stroke-opacity="1" stroke-dasharray="6 3" stroke-miterlimit="10" d="M 20 120 C 40 20 160 20 180 120 Z M 20 120 "/>
|
||||
<g clip-path="url(#clip-0)">
|
||||
<path fill-rule="nonzero" fill="rgb(20%, 40%, 70%)" fill-opacity="0.5" d="M 135 80 C 135 89.28125 131.3125 98.183594 124.75 104.75 C 118.183594 111.3125 109.28125 115 100 115 C 90.71875 115 81.816406 111.3125 75.25 104.75 C 68.6875 98.183594 65 89.28125 65 80 C 65 70.71875 68.6875 61.816406 75.25 55.25 C 81.816406 48.6875 90.71875 45 100 45 C 109.28125 45 118.183594 48.6875 124.75 55.25 C 131.3125 61.816406 135 70.71875 135 80 "/>
|
||||
</g>
|
||||
<g fill="rgb(0%, 0%, 0%)" fill-opacity="1">
|
||||
<use xlink:href="#glyph-0-0" x="70" y="140"/>
|
||||
<use xlink:href="#glyph-0-1" x="79.298828" y="140"/>
|
||||
<use xlink:href="#glyph-0-2" x="86.652344" y="140"/>
|
||||
<use xlink:href="#glyph-0-2" x="91.585938" y="140"/>
|
||||
<use xlink:href="#glyph-0-3" x="96.519531" y="140"/>
|
||||
<use xlink:href="#glyph-0-4" x="103.861328" y="140"/>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 6.0 KiB |
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env bash
|
||||
# Regenerates the vector-tool exports of `tests/svg_clean.rs` (V1-2.2, contract §9.2) with
|
||||
# the tools installed on the development machine; each file name carries the tool and its
|
||||
# version. Run from this folder: bash generate.sh. The editors' own exports (Inkscape,
|
||||
# Illustrator, Figma, Affinity) come from the owner, under owner/ (see README.md).
|
||||
set -euo pipefail
|
||||
|
||||
cairo_version=$(python3 -I -c 'import cairo; print(cairo.cairo_version_string())')
|
||||
pycairo_version=$(python3 -I -c 'import cairo; print(cairo.version)')
|
||||
prefix="cairo-${cairo_version}-pycairo-${pycairo_version}"
|
||||
|
||||
python3 -I - "$prefix" <<'EOF'
|
||||
import sys
|
||||
import cairo
|
||||
|
||||
prefix = sys.argv[1]
|
||||
|
||||
def shapes(context):
|
||||
gradient = cairo.LinearGradient(0, 0, 200, 0)
|
||||
gradient.add_color_stop_rgba(0, 0.6, 0.3, 0.2, 1)
|
||||
gradient.add_color_stop_rgba(1, 0.9, 0.8, 0.6, 0.7)
|
||||
context.set_source(gradient)
|
||||
context.move_to(20, 120)
|
||||
context.curve_to(40, 20, 160, 20, 180, 120)
|
||||
context.close_path()
|
||||
context.fill_preserve()
|
||||
context.set_source_rgb(0.2, 0.2, 0.2)
|
||||
context.set_line_width(2)
|
||||
context.set_dash([6, 3])
|
||||
context.stroke()
|
||||
context.set_dash([])
|
||||
context.save()
|
||||
context.rectangle(60, 60, 80, 40)
|
||||
context.clip()
|
||||
context.set_source_rgba(0.2, 0.4, 0.7, 0.5)
|
||||
context.arc(100, 80, 35, 0, 6.2832)
|
||||
context.fill()
|
||||
context.restore()
|
||||
context.set_source_rgb(0, 0, 0)
|
||||
context.select_font_face('DejaVu Sans')
|
||||
context.set_font_size(12)
|
||||
context.move_to(70, 140)
|
||||
context.show_text('Garrot')
|
||||
|
||||
surface = cairo.SVGSurface(f'{prefix}-shapes.svg', 200, 150)
|
||||
shapes(cairo.Context(surface))
|
||||
surface.finish()
|
||||
|
||||
surface = cairo.SVGSurface(f'{prefix}-raster.svg', 200, 150)
|
||||
context = cairo.Context(surface)
|
||||
pixels = cairo.ImageSurface(cairo.FORMAT_RGB24, 8, 8)
|
||||
inner = cairo.Context(pixels)
|
||||
inner.set_source_rgb(0.8, 0.1, 0.1)
|
||||
inner.paint()
|
||||
context.set_source_surface(pixels, 10, 10)
|
||||
context.paint()
|
||||
surface.finish()
|
||||
EOF
|
||||
|
||||
magick_version=$(magick -version | sed -n 's/^Version: ImageMagick \([^ ]*\).*/\1/p')
|
||||
magick -size 200x150 xc:white -fill '#336699' -stroke '#222222' -strokewidth 2 \
|
||||
-draw 'circle 100,75 100,30 rectangle 10,10 60,40 polyline 10,140 60,100 110,140' \
|
||||
"imagemagick-${magick_version}-draw.svg"
|
||||
# The MVG path writes its style settings as bare text between the elements.
|
||||
printf 'viewbox 0 0 200 150\nfill "#336699"\ncircle 100,75 100,30\nrectangle 10,10 60,40\nstroke "#222222"\nfill none\npolyline 10,140 60,100 110,140\n' >drawing.mvg
|
||||
magick mvg:drawing.mvg "imagemagick-${magick_version}-mvg.svg"
|
||||
rm -f drawing.mvg
|
||||
ls -1 ./*.svg
|
||||
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg width="200" height="150" xmlns="http://www.w3.org/2000/svg">
|
||||
<circle cx="100" cy="75" r="45"/>
|
||||
<rect x="10" y="10" width="50" height="30"/>
|
||||
<polyline points="10,140 60,100 110,140 "/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 257 B |
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg width="200" height="150" xmlns="http://www.w3.org/2000/svg">
|
||||
fill:#336699; <circle cx="100" cy="75" r="45"/>
|
||||
<rect x="10" y="10" width="50" height="30"/>
|
||||
stroke:#222222;fill:none; <polyline points="10,140 60,100 110,140 "/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 295 B |
@@ -0,0 +1 @@
|
||||
Owner-supplied editor exports land here (see ../README.md).
|
||||
Reference in new issue
Block a user