TIKA-4857: embedded-limits maxDepth counts embedding levels, not parser layers - #3098
Open
dschmidt wants to merge 4 commits into
Open
TIKA-4857: embedded-limits maxDepth counts embedding levels, not parser layers#3098dschmidt wants to merge 4 commits into
dschmidt wants to merge 4 commits into
Conversation
# Conflicts: # CHANGES.txt
# Conflicts: # CHANGES.txt
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes how EmbeddedLimits.maxDepth is enforced so it counts embedding levels (container=0, first embedded=1, …) rather than the number of composite/parser layers a parse traverses, aligning runtime behavior with the EmbeddedLimits javadoc and TIKA-4857.
Changes:
- Add explicit embedding-depth tracking to
ParseRecordand use it for maxDepth checks inParsingEmbeddedDocumentExtractor. - Ensure embedded parsing via
UnpackExtractoralso updates the embedding-depth counter correctly. - Add a regression test that nests documents behind multiple composite layers and verifies maxDepth behavior; document the behavior change in
CHANGES.txt.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tika-pipes/tika-pipes-core/src/main/java/org/apache/tika/pipes/core/extractor/UnpackExtractor.java | Updates embedded depth tracking around embedded parses so maxDepth is enforced by embedding level, not parser layers. |
| tika-core/src/main/java/org/apache/tika/parser/ParseRecord.java | Introduces an embedding-depth counter (embeddedDepth) with enter/exit APIs used during embedded parsing. |
| tika-core/src/main/java/org/apache/tika/extractor/ParsingEmbeddedDocumentExtractor.java | Switches maxDepth enforcement to use embedding depth (+1 for the child) and brackets the embedded parse with enter/exit calls. |
| tika-core/src/test/java/org/apache/tika/extractor/EmbeddedDepthLimitTest.java | Adds regression coverage for maxDepth semantics under nested composite parsers. |
| CHANGES.txt | Notes the maxDepth semantics fix for the upcoming release. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| } | ||
| List<Metadata> documents = handler.getMetadataList(); | ||
| assertEquals(expectedDocuments, documents.size(), documents.toString()); | ||
| //the wrapper lists a document once it is finished, so the deepest comes first |
Comment on lines
+210
to
+212
| public void exitEmbedded() { | ||
| embeddedDepth--; | ||
| } |
Contributor
Author
There was a problem hiding this comment.
Guarded: exitEmbedded() without a matching enterEmbedded() throws IllegalStateException.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ParseRecord.depthis incremented for every composite parser a parse passes through. WithAutoDetectParserwrappingDefaultParserthat is two per document level, and the depth check compared that counter withmaxDepth + 1, somaxDepth=2parsed depth 1 only,maxDepth=3reached depth 2, and so on.maxDepth=0and1happened to work, which is what the existing tests cover.ParseRecordnow has an embedding depth thatParsingEmbeddedDocumentExtractorandUnpackExtractorraise around the child's parse, and the limit is checked against that: withmaxDepth=N, documents at depth N are parsed and their children are not, as theEmbeddedLimitsjavadoc describes. The composite counter stays as it is for its other uses (top-level detection, handler decoration).The new test nests a parser five levels deep behind two composite layers and fails on main for maxDepth 2, 3 and 5.
https://issues.apache.org/jira/browse/TIKA-4857