Skip to content

TIKA-4857: embedded-limits maxDepth counts embedding levels, not parser layers - #3098

Open
dschmidt wants to merge 4 commits into
apache:mainfrom
dschmidt:embedded-depth-limit
Open

TIKA-4857: embedded-limits maxDepth counts embedding levels, not parser layers#3098
dschmidt wants to merge 4 commits into
apache:mainfrom
dschmidt:embedded-depth-limit

Conversation

@dschmidt

Copy link
Copy Markdown
Contributor

ParseRecord.depth is incremented for every composite parser a parse passes through. With AutoDetectParser wrapping DefaultParser that is two per document level, and the depth check compared that counter with maxDepth + 1, so maxDepth=2 parsed depth 1 only, maxDepth=3 reached depth 2, and so on. maxDepth=0 and 1 happened to work, which is what the existing tests cover.

ParseRecord now has an embedding depth that ParsingEmbeddedDocumentExtractor and UnpackExtractor raise around the child's parse, and the limit is checked against that: with maxDepth=N, documents at depth N are parsed and their children are not, as the EmbeddedLimits javadoc 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ParseRecord and use it for maxDepth checks in ParsingEmbeddedDocumentExtractor.
  • Ensure embedded parsing via UnpackExtractor also 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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworded.

Comment on lines +210 to +212
public void exitEmbedded() {
embeddedDepth--;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guarded: exitEmbedded() without a matching enterEmbedded() throws IllegalStateException.

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.

2 participants