Skip to content

Empty XML comment in SVG panics the minifier (500) #1691

Description

@diegoatpitch

Version 4.0.11
Processing any SVG that contains an empty XML comment (<!---->) causes the SVG minifier to panic and return to the client as HTTP 500.

Minimal reproduction

<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10"><!----><rect width="10" height="10"/></svg>

Replacing <!----> with any non-empty body (<!--x-->) renders fine.

Stack trace (from prod logs)

runtime error: index out of range [0] with length 0
/app/processing/svg/minify/minify.go:146  (*minifier).cleanupWalk.func1.(*minifier).cleanupWalk.1
/app/xmlparser/node.go:22                  (*Node).FilterChildren.func1
/usr/local/go/src/slices/slices.go:109     slices.IndexFunc[...]
/usr/local/go/src/slices/slices.go:240     slices.DeleteFunc[...]
/app/xmlparser/node.go:21                  (*Node).FilterChildren
/app/processing/svg/minify/minify.go:138   (*minifier).cleanupWalk.func1
/app/processing/svg/minify/minify.go:168   (*minifier).cleanupWalk.func1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions