Uploaded image for project: 'Batik'
  1. Batik
  2. BATIK-1227

[PATCH] Image filters encoded with Base64 in the SVG throw "Content not allowed in prolog" exception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.9
    • None
    • Bridge
    • None
    • Patch

    Description

      Having this SVG:

      <svg id="note" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="20" height="20" viewBox="0 0 20 20">
        <defs>
          <style>
            .cls-1 {
              fill: #e99915;
              filter: url(#filter);
            }
      
            .cls-1, .cls-2, .cls-3, .cls-4, .cls-5 {
              fill-rule: evenodd;
            }
      
            .cls-2 {
              fill: #cbcbcb;
              filter: url(#filter-2);
            }
      
            .cls-3 {
              fill: red;
              filter: url(#filter-3);
            }
      
            .cls-4 {
              fill: #b04a1a;
            }
      
            .cls-5 {
              fill: #cd803c;
            }
          </style>
          <filter id="filter" x="2" y="2" width="16" height="16" filterUnits="userSpaceOnUse">
            <feImage preserveAspectRatio="none" x="2" y="2" width="16" height="16" result="image" xlink:href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAxNiAxNiI+CiAgPGRlZnM+CiAgICA8c3R5bGU+CiAgICAgIC5jbHMtMSB7CiAgICAgICAgZmlsbDogdXJsKCNsaW5lYXItZ3JhZGllbnQpOwogICAgICB9CiAgICA8L3N0eWxlPgogICAgPGxpbmVhckdyYWRpZW50IGlkPSJsaW5lYXItZ3JhZGllbnQiIHgxPSI4IiB5MT0iMTYiIHgyPSI4IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CiAgICAgIDxzdG9wIG9mZnNldD0iMCIgc3RvcC1jb2xvcj0iI2JkNzUzNSIvPgogICAgICA8c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiNkNjg2M2YiLz4KICAgIDwvbGluZWFyR3JhZGllbnQ+CiAgPC9kZWZzPgogIDxyZWN0IGNsYXNzPSJjbHMtMSIgd2lkdGg9IjE2IiBoZWlnaHQ9IjE2Ii8+Cjwvc3ZnPgo="/>
            <feComposite result="composite" operator="in" in2="SourceGraphic"/>
            <feBlend result="blend" in2="SourceGraphic"/>
          </filter>
          <filter id="filter-2" x="3" y="3" width="14" height="14" filterUnits="userSpaceOnUse">
            <feImage preserveAspectRatio="none" x="3" y="3" width="14" height="14" result="image" xlink:href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iMTQiIGhlaWdodD0iMTQiIHZpZXdCb3g9IjAgMCAxNCAxNCI+CiAgPGRlZnM+CiAgICA8c3R5bGU+CiAgICAgIC5jbHMtMSB7CiAgICAgICAgZmlsbDogdXJsKCNsaW5lYXItZ3JhZGllbnQpOwogICAgICB9CiAgICA8L3N0eWxlPgogICAgPGxpbmVhckdyYWRpZW50IGlkPSJsaW5lYXItZ3JhZGllbnQiIHgxPSI3IiB5MT0iMTQiIHgyPSI3IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CiAgICAgIDxzdG9wIG9mZnNldD0iMCIgc3RvcC1jb2xvcj0iI2ZmYjk1NyIvPgogICAgICA8c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiNmZmVmNWYiLz4KICAgIDwvbGluZWFyR3JhZGllbnQ+CiAgPC9kZWZzPgogIDxyZWN0IGNsYXNzPSJjbHMtMSIgd2lkdGg9IjE0IiBoZWlnaHQ9IjE0Ii8+Cjwvc3ZnPgo="/>
            <feComposite result="composite" operator="in" in2="SourceGraphic"/>
            <feBlend result="blend" in2="SourceGraphic"/>
          </filter>
          <filter id="filter-3" x="12" y="12" width="6" height="6" filterUnits="userSpaceOnUse">
            <feImage preserveAspectRatio="none" x="12" y="12" width="6" height="6" result="image" xlink:href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iNiIgaGVpZ2h0PSI2IiB2aWV3Qm94PSIwIDAgNiA2Ij4KICA8ZGVmcz4KICAgIDxzdHlsZT4KICAgICAgLmNscy0xIHsKICAgICAgICBmaWxsOiB1cmwoI2xpbmVhci1ncmFkaWVudCk7CiAgICAgIH0KICAgIDwvc3R5bGU+CiAgICA8bGluZWFyR3JhZGllbnQgaWQ9ImxpbmVhci1ncmFkaWVudCIgeTE9IjAuMzkyIiB4Mj0iNiIgeTI9IjUuNjA4IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CiAgICAgIDxzdG9wIG9mZnNldD0iMCIgc3RvcC1jb2xvcj0iI2I2NzMwNCIvPgogICAgICA8c3RvcCBvZmZzZXQ9IjEiIHN0b3AtY29sb3I9IiNmOGJlNGMiLz4KICAgIDwvbGluZWFyR3JhZGllbnQ+CiAgPC9kZWZzPgogIDxyZWN0IGNsYXNzPSJjbHMtMSIgd2lkdGg9IjYiIGhlaWdodD0iNiIvPgo8L3N2Zz4K"/>
            <feComposite result="composite" operator="in" in2="SourceGraphic"/>
            <feBlend result="blend" in2="SourceGraphic"/>
          </filter>
        </defs>
        <path id="Outer" class="cls-1" d="M2,2H18V12.719L12.563,18H2V2Z"/>
        <path id="Fill" class="cls-2" d="M3,3H17v9.719L12.563,17H3V3Z"/>
        <path id="FillCorner" class="cls-3" d="M13.031,13v3L12,18l6-6-2,1H13.031Z"/>
        <path id="Lines" class="cls-4" d="M6,7V6h8V7H6Zm0,3V9h8v1H6Zm0,3V12h4v1H6Z"/>
        <path id="Corner" class="cls-5" d="M18,12v0.707L17.707,13,13,17.707,12.707,18H12V12h6Zm-5,1v3.293L16.293,13H13Z"/>
      </svg>
      

      You get:

      ERROR org.apache.fop.apps.FOUserAgent - SVG graphic could not be built. Reason: org.apache.batik.bridge.BridgeException: Content is not allowed in prolog.
      [exec] org.apache.batik.bridge.BridgeException: Content is not allowed in prolog.
      [exec] at org.apache.batik.bridge.BridgeContext.getReferencedNode(BridgeContext.java:788)
      [exec] at org.apache.batik.bridge.BridgeContext.getReferencedElement(BridgeContext.java:804)
      [exec] at org.apache.batik.bridge.PaintServer.convertURIPaint(PaintServer.java:365)
      [exec] at org.apache.batik.bridge.PaintServer.convertPaint(PaintServer.java:273)
      [exec] at org.apache.batik.bridge.PaintServer.convertFillPaint(PaintServer.java:242)
      [exec] at org.apache.batik.bridge.PaintServer.convertFillAndStroke(PaintServer.java:160)
      [exec] at org.apache.batik.bridge.SVGShapeElementBridge.createShapePainter(SVGShapeElementBridge.java:117)
      [exec] at org.apache.batik.bridge.SVGRectElementBridge.createShapePainter(SVGRectElementBridge.java:153)
      [exec] at org.apache.batik.bridge.SVGShapeElementBridge.buildGraphicsNode(SVGShapeElementBridge.java:91)
      [exec] at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode(GVTBuilder.java:224)
      [exec] at org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:171)

      The fix is to compose the base URL and the fragment into a ParsedURLData:

      In the ParsedURLDataProtocolHandler the method:

        public ParsedURLData parseURL(ParsedURL baseURL, String urlStr) {
              // No relative form...
              return parseURL(urlStr);
          }
      

      should change to:

        public ParsedURLData parseURL(ParsedURL baseURL, String urlStr) {
             if (urlStr.startsWith("#")) {
                // Use the base, it contains the encoded document
                ParsedURLData parseURL = parseURL(baseURL.toString());
                // .. and pass the reference
                parseURL.ref = urlStr.substring(1); // Skip the #
                return parseURL;
              } else {
                // No relative form...
                return parseURL(urlStr);
              }
        }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              dc33 Dan Caprioara
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: