apupier opened a new pull request, #30654:
URL: https://github.com/apache/camel/pull/30654

   # Description
   
   Fixes [CAMEL-27428](https://issues.apache.org/jira/browse/CAMEL-27428): 
`XsdJsonSecurityTest.nestingDepthIsLimited` fails about 10% of the time with
   
   ```
   Expecting throwable message: null to contain: "The JSON is nested deeper 
than 512"
   Throwable that failed the check: java.lang.StackOverflowError
       at 
org.apache.camel.dataformat.xsdjson.JsonToXml.checkUnknown(JsonToXml.java:161)
       ...
   ```
   
   **Cause:** `JsonToXml` recurses through about six frames per nesting level 
(`writeElement` → `writeGroup` → `writeMemberOrGroup` → `writeMember` → ...). 
The depth limit (512) is checked per element, but on a thread with a small 
stack the stack is exhausted before the limit is reached. The 
`StackOverflowError` has no message, hence the `null`.
   
   **Reproduction without the fix** (the default JIT-compiled frames are small 
enough to pass, so force the interpreter and a small stack):
   
   ```
   mvn test -pl components/camel-xsd-json -am 
-Dtest=XsdJsonSecurityTest#nestingDepthIsLimited \
     -Dsurefire.failIfNoSpecifiedTests=false -DfailIfNoTests=false \
     "-Dcamel.surefire.fork.additional-vmargs=-Xint -Xss256k"
   ```
   
   Fails with the exact assertion of the ticket at 192k, 256k and 384k; passes 
at 512k. With the fix, 256k passes.
   
   **Changes:**
   - `JsonToXml.write()` turns a `StackOverflowError` into an 
`IllegalArgumentException`, so deeply nested input from an untrusted sender 
gets a normal error instead of an `Error` escaping from the data format.
   - `XsdJsonSecurityTest` accepts either the depth limit message or the stack 
message for the JSON to XML direction, as it already does for the XML to JSON 
direction (the XML parser of the JDK may have a lower limit).
   
   No documentation change: the documented limit and its wording are unchanged.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [x] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
   
   ---
   _Bob (IBM Bob 2.2.1) on behalf of apupier_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to