BigBadaboom / androidsvg

SVG rendering library for Android
http://bigbadaboom.github.io/androidsvg/
Apache License 2.0
1.2k stars 227 forks source link

Cannot parse the SVG: "Malformed rule set in <style> element" #246

Closed namchuai closed 2 years ago

namchuai commented 2 years ago

Describe the bug Hello, thank you for this great library!

Currently, I'm integrated AndroidSVG library with Glide to display SVG and some of the SVGs cannot be displayed. The problem is AndroidSVG can't parse the SVG.

Expected behavior SVG parsed successfully.

Stack traces

I/Glide: Root cause (1 of 1)
    java.io.IOException: Cannot load SVG from stream
        at com.aliens.android.util.glide.SvgDecoder.decode(SvgDecoder.java:37)
        at com.aliens.android.util.glide.SvgDecoder.decode(SvgDecoder.java:16)
        at com.bumptech.glide.load.engine.DecodePath.decodeResourceWithList(DecodePath.java:92)
        at com.bumptech.glide.load.engine.DecodePath.decodeResource(DecodePath.java:70)
        at com.bumptech.glide.load.engine.DecodePath.decode(DecodePath.java:59)
        at com.bumptech.glide.load.engine.LoadPath.loadWithExceptionList(LoadPath.java:76)
        at com.bumptech.glide.load.engine.LoadPath.load(LoadPath.java:57)
        at com.bumptech.glide.load.engine.DecodeJob.runLoadPath(DecodeJob.java:524)
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromFetcher(DecodeJob.java:488)
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromData(DecodeJob.java:474)
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromRetrievedData(DecodeJob.java:426)
        at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherReady(DecodeJob.java:390)
        at com.bumptech.glide.load.engine.SourceGenerator.onDataFetcherReady(SourceGenerator.java:176)
        at com.bumptech.glide.load.engine.DataCacheGenerator.onDataReady(DataCacheGenerator.java:94)
        at com.bumptech.glide.load.model.FileLoader$FileFetcher.loadData(FileLoader.java:79)
        at com.bumptech.glide.load.engine.DataCacheGenerator.startNext(DataCacheGenerator.java:74)
        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:50)
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310)
        at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279)
        at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:234)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:920)
        at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:393)
     Caused by: com.caverock.androidsvg.SVGParseException: SVG parse error: Malformed rule set in <style> element
        at com.caverock.androidsvg.SVGParser.parse(SVGParser.java:611)
        at com.caverock.androidsvg.SVG.getFromInputStream(SVG.java:144)
        at com.aliens.android.util.glide.SvgDecoder.decode(SvgDecoder.java:28)
        at com.aliens.android.util.glide.SvgDecoder.decode(SvgDecoder.java:16) 
        at com.bumptech.glide.load.engine.DecodePath.decodeResourceWithList(DecodePath.java:92) 
        at com.bumptech.glide.load.engine.DecodePath.decodeResource(DecodePath.java:70) 
        at com.bumptech.glide.load.engine.DecodePath.decode(DecodePath.java:59) 
        at com.bumptech.glide.load.engine.LoadPath.loadWithExceptionList(LoadPath.java:76) 
        at com.bumptech.glide.load.engine.LoadPath.load(LoadPath.java:57) 
        at com.bumptech.glide.load.engine.DecodeJob.runLoadPath(DecodeJob.java:524) 
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromFetcher(DecodeJob.java:488) 
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromData(DecodeJob.java:474) 
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromRetrievedData(DecodeJob.java:426) 
        at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherReady(DecodeJob.java:390) 
        at com.bumptech.glide.load.engine.SourceGenerator.onDataFetcherReady(SourceGenerator.java:176) 
        at com.bumptech.glide.load.engine.DataCacheGenerator.onDataReady(DataCacheGenerator.java:94) 
        at com.bumptech.glide.load.model.FileLoader$FileFetcher.loadData(FileLoader.java:79) 
        at com.bumptech.glide.load.engine.DataCacheGenerator.startNext(DataCacheGenerator.java:74) 
        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:50) 
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310) 
        at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279) 
        at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:234) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:920) 
        at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:393) 
     Caused by: org.xml.sax.SAXException: Malformed rule set in <style> element
        at com.caverock.androidsvg.CSSParser.parseDeclarations(CSSParser.java:743)
        at com.caverock.androidsvg.CSSParser.parseRule(CSSParser.java:667)
        at com.caverock.androidsvg.CSSParser.parseRuleset(CSSParser.java:649)
        at com.caverock.androidsvg.CSSParser.parse(CSSParser.java:293)
        at com.caverock.androidsvg.SVGParser.parseCSSStyleSheet(SVGParser.java:4009)
        at com.caverock.androidsvg.SVGParser.endElement(SVGParser.java:807)
        at org.apache.harmony.xml.ExpatParser.endElement(ExpatParser.java:167)
        at org.apache.harmony.xml.ExpatParser.appendBytes(Native Method)
        at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:526)
        at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:487)
        at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:324)
        at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:287)
        at com.caverock.androidsvg.SVGParser.parse(SVGParser.java:599)
        at com.caverock.androidsvg.SVG.getFromInputStream(SVG.java:144) 
        at com.aliens.android.util.glide.SvgDecoder.decode(SvgDecoder.java:28) 
        at com.aliens.android.util.glide.SvgDecoder.decode(SvgDecoder.java:16) 
        at com.bumptech.glide.load.engine.DecodePath.decodeResourceWithList(DecodePath.java:92) 
        at com.bumptech.glide.load.engine.DecodePath.decodeResource(DecodePath.java:70) 
        at com.bumptech.glide.load.engine.DecodePath.decode(DecodePath.java:59) 
        at com.bumptech.glide.load.engine.LoadPath.loadWithExceptionList(LoadPath.java:76) 
        at com.bumptech.glide.load.engine.LoadPath.load(LoadPath.java:57) 
        at com.bumptech.glide.load.engine.DecodeJob.runLoadPath(DecodeJob.java:524) 
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromFetcher(DecodeJob.java:488) 
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromData(DecodeJob.java:474) 
        at com.bumptech.glide.load.engine.DecodeJob.decodeFromRetrievedData(DecodeJob.java:426) 
        at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherReady(DecodeJob.java:390) 
        at com.bumptech.glide.load.engine.SourceGenerator.onDataFetcherReady(SourceGenerator.java:176) 
        at com.bumptech.glide.load.engine.DataCacheGenerator.onDataReady(DataCacheGenerator.java:94) 
        at com.bumptech.glide.load.model.FileLoader$FileFetcher.loadData(FileLoader.java:79) 
        at com.bumptech.glide.load.engine.DataCacheGenerator.startNext(DataCacheGenerator.java:74) 
        at com.bumptech.glide.load.engine.SourceGenerator.startNext(SourceGenerator.java:50) 
        at com.bumptech.glide.load.engine.DecodeJob.runGenerators(DecodeJob.java:310) 
        at com.bumptech.glide.load.engine.DecodeJob.runWrapped(DecodeJob.java:279) 
        at com.bumptech.glide.load.engine.DecodeJob.run(DecodeJob.java:234) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:920) 
        at com.bumptech.glide.load.engine.executor.GlideExecutor$DefaultThreadFactory$1.run(GlideExecutor.java:393) 

SVG file https://storage.opensea.io/files/cf2f40b1f6ceccb00be8036306290ff5.svg https://storage.opensea.io/files/edd982e92a39ddda0a80f481c7ffec33.svg

Device Any devices

namchuai commented 2 years ago

I upgrade from 1.2.1 to 1.4 and the issue is no longer reproducible. Thank you!