This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-neethi.git
The following commit(s) were added to refs/heads/master by this push:
new fdaf27e Add memory exhaustion protection to Axiom path as well
fdaf27e is described below
commit fdaf27e3f093a4d65ce12df271d7922c74213eab
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Tue Sep 15 10:37:07 2026 +0100
Add memory exhaustion protection to Axiom path as well
---
src/main/java/org/apache/neethi/PolicyBuilder.java | 10 ++++++++++
.../neethi/builders/converters/OMToDOMConverter.java | 17 +++++++++++++++--
2 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/neethi/PolicyBuilder.java
b/src/main/java/org/apache/neethi/PolicyBuilder.java
index ee6c9c8..f4e3cdf 100644
--- a/src/main/java/org/apache/neethi/PolicyBuilder.java
+++ b/src/main/java/org/apache/neethi/PolicyBuilder.java
@@ -379,6 +379,16 @@ public class PolicyBuilder {
}
}
+ /**
+ * Returns whether a policy parse is in progress on the current thread,
i.e.
+ * whether an ambient budget is active. The converter layer uses this to
+ * decide whether an assertion-subtree materialization must be charged
+ * against the parse's maxElements/maxAttributes budget.
+ */
+ public static boolean hasAmbientParseBudget() {
+ return CURRENT_BUDGET.get() != null;
+ }
+
/**
* Charges one materialized element against the budget of the policy parse
* in progress on the current thread, if any. Called by the converter
diff --git
a/src/main/java/org/apache/neethi/builders/converters/OMToDOMConverter.java
b/src/main/java/org/apache/neethi/builders/converters/OMToDOMConverter.java
index a26369e..5f864df 100644
--- a/src/main/java/org/apache/neethi/builders/converters/OMToDOMConverter.java
+++ b/src/main/java/org/apache/neethi/builders/converters/OMToDOMConverter.java
@@ -26,13 +26,26 @@ import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMXMLBuilderFactory;
+import org.apache.neethi.PolicyBuilder;
+
/**
- *
+ *
*/
public class OMToDOMConverter extends AbstractOMConverter implements
Converter<OMElement, Element> {
public Element convert(OMElement s) {
-
+ // When a policy parse is in progress, route through
StaxToDOMConverter:
+ // it materializes the assertion subtree while streaming and charges
+ // every node against the parse budget (chargeAmbientElement /
+ // chargeAmbientAttributes), throwing as soon as maxElements /
+ // maxAttributes is exceeded. The DOOM builder below does no budget
+ // accounting, so an assertion subtree supplied as an Axiom OMElement
+ // would otherwise bypass those budgets entirely. Outside a parse (no
+ // ambient budget) the faster DOOM path is kept unchanged.
+ if (PolicyBuilder.hasAmbientParseBudget()) {
+ return new StaxToDOMConverter().convert(s.getXMLStreamReader());
+ }
+
try {
return (Element) OMXMLBuilderFactory.createStAXOMBuilder(
OMAbstractFactory.getMetaFactory(OMAbstractFactory.FEATURE_DOM).getOMFactory(),