Skip to content

fix: check for loops in HrefIter - #1218

Merged
LaurenzV merged 2 commits into
linebender:mainfrom
Its-Just-Nans:fix-1191
Nov 4, 2026
Merged

LaurenzV merged 2 commits into
linebender:mainfrom
Its-Just-Nans:fix-1191

Conversation

@Its-Just-Nans

Copy link
Copy Markdown
Contributor

Possible fix for #1191

@LaurenzV

LaurenzV commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Thank you! The fix looks good, i just applied two tweaks:

  • I created a custom struct for keeping track of visited nodes, which switches from an inline array to a hashmap only if the list gets too long. This is to avoid allocating in the common case where we don't have any (or only few) links.
  • I turned the tests into visreg tests. I generally prefer visual tests, because they allow us to easily compare against other browsers, and it's also easier to see whether it actually has the intended result. 😄 Hope that makes sense.

@LaurenzV LaurenzV changed the title fix: check for loops in HrefIter fix: check for loops in HrefIter Nov 4, 2026
@LaurenzV
LaurenzV merged commit 107c312 into linebender:main Nov 4, 2026
5 checks passed
@Its-Just-Nans

Its-Just-Nans commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Thank you! The fix looks good, i just applied two tweaks:

Yes good idea !

I also think that maybe we could add a threshold on the HrefIter length (It would be used to limit the stack overflow if there is a long chain of url(#element) on some edge cases)

Kinda like we have a check here

if depth > 1024 {
return Err(Error::NodesLimitReached);
}

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

usvg hangs for ever on an xlink:href loop that does not include the first gradient

2 participants