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

Reset xmlXPathContext state variables before each evaluation #3386

Closed
wants to merge 2 commits into from

Conversation

flavorjones
Copy link
Member

@flavorjones flavorjones commented Dec 20, 2024

What problem is this PR intended to solve?

In #3378 we implemented re-used of xmlXPathContext objects for performance.

If we're re-using the xmlXPathContext object, there's a chance that the context variables will be trashed by recursive custom functions.

In #3378 (comment), @nwellnhof advised:

Note that if you use a single XPath context and support custom XPath
extension functions, a custom function could evaluate XPath
expressions recursively which will lead to corruption of context
variables. This is mostly due to some design mistakes in libxml2.

So let's set these context variables back to their default.

Have you included adequate test coverage?

Functional test coverage should be sufficient to show the features still work, but I did not add test coverage that would have revealed a bug.

Does this change affect the behavior of either the C or the Java implementations?

CRuby only fix

If we're re-using the xmlXPathContext object, there's a chance that
the context variables will be trashed by recursive custom functions.

In #3378 (comment),
Nick advised:

> Note that if you use a single XPath context and support custom XPath
> extension functions, a custom function could evaluate XPath
> expressions recursively which will lead to corruption of context
> variables. This is mostly due to some design mistakes in libxml2.

So let's set these context variables back to their default.
@flavorjones
Copy link
Member Author

After chatting more with Nick, this approach is not right, closing.

auto-merge was automatically disabled December 20, 2024 19:31

Pull request was closed

@flavorjones flavorjones deleted the flavorjones-reuse-xpathcontext-safety branch December 21, 2024 19:29
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.

1 participant