Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stuck in parsing css in some svg. #206

Closed
kkwpsv opened this issue Aug 24, 2021 · 12 comments
Closed

Stuck in parsing css in some svg. #206

kkwpsv opened this issue Aug 24, 2021 · 12 comments
Assignees

Comments

@kkwpsv
Copy link

kkwpsv commented Aug 24, 2021

The stack when stuck is as below:

image

Here is two svgs which caused stuck.
svg.zip

@paulushub paulushub self-assigned this Aug 24, 2021
@alo00
Copy link

alo00 commented Sep 9, 2021

I have the same problem with this file.
freeze.zip

It also freezes the UI if in a SvgViewBox like this :

    <Grid>
        <svgc:SvgViewbox Stretch="Fill"
                         Source= "W:/New Folder/freeze.svg">
        </svgc:SvgViewbox>
    </Grid>

But it works with SharpVectors 1.5!

Maybe related to some font definition in SVG?

@kkwpsv
Copy link
Author

kkwpsv commented Sep 9, 2021

It may be realted to regular expression backtracking.

@marksolbergerbjorkerot
Copy link

marksolbergerbjorkerot commented Sep 20, 2021

Reproduced fail during css-parsing with the following data:
failed-svg-regexp.zip. RegEx.Match hangs and gets caught in a loop during css-processing in CssUnknownRule

@paulushub
Copy link
Contributor

@marksolbergerbjorkerot Thanks for tracking this issue. There is another problem with this issue; the original SVG test file contains embedded WOFF2 format font, which is not fully supported by the SharpVectors. I am currently trying to complete that support and then take on the CSS parsing.

@marksolbergerbjorkerot
Copy link

@paulushub - it seems that CssRuleList never breaks the while-loop when no at-rules have been able to be parsed. It just keeps looping the same css over and over. Changing the UnknownCssRule regex-pattern no ^@[^;]+;? (making the last semi-colon optional) will render a match on the rule for cases where no semicolon exists and the while-loop will break.

@paulushub
Copy link
Contributor

@marksolbergerbjorkerot I have completed the WOFF1/WOFF2 decoder codes and started testing this issue.
It seems the only fix required here is _reSplitCss in the CssStyleDeclaration.
Changing this to the fix in your fork/commit (change _reSplitCss by removing match any) seems to resolve both issues reported above.

private static readonly Regex _reSplitCss = new Regex(@"([^:\s]+)*\s*:\s*([^;]+);");

// changed to

private static readonly Regex _reSplitCss = new Regex(@"([^:\s]+)\s*:\s*([^;]+);");

paulushub added a commit that referenced this issue Sep 27, 2021
- Reworked and completed the WOFF1 and WOFF2 support
- Restoration of FontFamily names in WOFF1 when stripped out. Issue #123
- Fixed CSS parsing issue #206 - credit @marksolbergerbjorkerot
@paulushub
Copy link
Contributor

@kkwpsv @alo00 @marksolbergerbjorkerot It seems this issue is resolved by the latest commit. Please can you verify this fix.

@kkwpsv The embedded WOFF2 fonts are never used. Are you using these fonts? The fonts were decoded and successfully tested, but no verification is done in your test file, since there is no text to be rendered.

@kkwpsv
Copy link
Author

kkwpsv commented Sep 30, 2021

I have test the latest version with my sample file, it works fine.
The svg file is not from myself, i don't know why it embed font and not use.
I have modified it to use font embeded. It seems also works fine.

svg with woff2 sample.zip

@paulushub
Copy link
Contributor

@kkwpsv Thanks for the updates.

@Whiletru3
Copy link

Is there any plan for a new release including this fix ?

Thanks

@paulushub
Copy link
Contributor

@Whiletru3 Will trying to get it out by Monday. Currently, busy looking for a new job 😢

@Whiletru3
Copy link

@paulushub Thanks a lot :) Good luck for your search 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants