Repository navigation
Conversation
… limit Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
kanat
left a comment
There was a problem hiding this comment.
Text review: 4 unclear of 8
Three code comments are hard to read cold (T1.1), and the PR opening names encoding/xml and #2600 (T1.2, nit): suggested opening: "A small Word or OpenDocument file with deeply nested XML made the router allocate far more memory than the file is long. The workbook reader already refused such files. The Word and OpenDocument readers now refuse a part nested deeper than the same limit, as too large."
kanat
left a comment
There was a problem hiding this comment.
[security R1] VERDICT: GO
I checked every XML decoder in the Word and OpenDocument readers. All six now go through the depth-capped reader, and the workbook reader keeps its own cap. I tried prefixed and default namespaces, self-closing elements, comments and CDATA between levels, end tags that were never opened, entities declared in a DTD, and a part stored twice in the archive. Each one is refused or read within the limit. The refusal text is fixed wording plus the part name, so it shows nothing about the server.
Two small things, both optional:
| id | where | what |
|---|---|---|
| S1.1 Nit | odt.go:114 | No test fails if the cap is taken off the OpenDocument body reader alone |
| S1.2 Nit | xmldepth.go:40 | The depth reader forgets its error after it returns it |
kanat
left a comment
There was a problem hiding this comment.
VERDICT: NO-GO
Reviewed 5dae1dc on top of main 6dff757. The six Word and OpenDocument decoders all go through the depth limit, and the new tests hold up: I ran 24 mutants and 22 were killed. One gap blocks the merge (R1.1): nothing checks that a broken part that is not nested too deep is still refused as corrupt.
[Nit] R1.2 (lines outside the diff). Two more comments are no longer true. In xlsx.go, the maxXMLDepth comment (line 55) says the limit is for "an element of a workbook part", and the overLimit comment (line 389) says "a workbook past one of the limits". Both now also apply to Word and OpenDocument parts. In extract.go, the unreadable comment (lines 198-199) still says "otherwise a file that is corrupt", but it now answers too large for an over-limit error. The inline comment on line 207 covers the rest.
Author questions
- The shared
nestingtype, rather than running Word and OpenDocument parts throughlimitedTokens: accepted.limitedTokenscarries limits that only make sense for a workbook (element, cell and run counts, the tag guard, the deadline tick), and they would refuse or slow ordinary documents. The depth rule and its error are written once, innesting.enter. - The workbook error text change: R1.3, inline.
- The ODT body decoder mutant is equivalent, as the author says.
odtListStylesreads all ofcontent.xmlwith the same decoder before the body reader runs (odt.go:43-47), so the body reader never sees a part nested past the limit. When I also made the list-style pass skipcontent.xml, both new tests killed the mutant.
Two items in code this PR does not change will go to Linear tickets.
CI: the PR is a draft, so the go and integration jobs were skipped. They run when it is marked ready. Locally on the head, go vet and go test ./internal/knowledge/... pass, and the new tests pass 10 runs in a row.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…files Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…s own cap Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ts reason Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
kanat
left a comment
There was a problem hiding this comment.
VERDICT: NO-GO
Reviewed 5973741 on main 6dff757 (draft, so no CI runs; go and integration are skipped).
Earlier findings:
- R1.1 fixed:
TestABrokenWordOrOpenDocumentPartIsRefusedAsCorruptkills the mutant that answers every XML error as TooLarge. - R1.2 and T1.1 fixed: the five comments are true now.
- R1.3 fixed: each format keeps its wording. Changing either
writerto "a program" fails its test. - R1.6 fixed in code: the pages text is the base text, byte for byte, when
errors.AsfindsPageLimit. Unwrapping it in pdf.go, or flipping the check in documents.go either way, fails the new tests. - T1.2 fixed: the PR body opens with the rewrite.
- S1.1 and S1.2 fixed: a plain decoder in the ODT body reader, and removing the sticky error, each fail a test. Replacing
newDocumentDecoderat each of the six sites (docx.go 83, 112, 157, 227; odt.go 69, 114) fails a test.
New finding:
- R2.1 [Should fix] The second
PageLimitsite, extract.go:320, is not pinned. That is the page check for every file that is not a PDF. Removing the wrap there passes the extract and api suites, and a Word file over the page limit is then told "too large or too deeply nested" instead of "(at most 100 pages)". That is a wording change from base. Probe (reverted): a.docx with<w:lastRenderedPageBreak/>in the 2nd and 3rd paragraphs, read withMaxPages: 1. It passes on head and fails under the mutant. The inline comment has the row.
R1.4, R1.5 and the S1.3 follow-ups stay tickets.
Suites on head (same as base): go test ./internal/knowledge/..., api TestDocumentFailureSuite and TestAreaSuite, and go vet with and without the integration tag pass. The api integration suite was not run (needs a DB). 17 mutants checked, 1 survived (R2.1).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
kanat
left a comment
There was a problem hiding this comment.
VERDICT: GO
Delta round 3 of this PR, head 874f1fc (base origin/main 6dff757; no merge needed, the old head is an ancestor).
Prior findings:
- R2.1 fixed. TestAWordFileOverThePageLimitIsToldHowManyPagesAreRead fails when the PageLimit wrap at extract/extract.go:320 is removed (it gets the generic "too large or too deeply nested" wording) and passes once restored.
- R1.1, R1.2, R1.3, R1.6, T1.1, T1.2, S1.1, S1.2: fixed in round 2. This delta does not touch them.
- R1.4, R1.5: Question items with a ticket, not touched by this delta. The ticket policy stands.
New findings: none.
Checks:
- git diff 5973741..874f1fc --stat: one file, acceleration/internal/api/documents_unit_test.go, 25 insertions.
- go test ./internal/api -run TestDocumentFailureSuite: passes on head. Mutant: fails the new test. Restored: passes.
- go test ./internal/knowledge/...: all packages pass.
- go vet ./internal/api ./internal/knowledge/...: clean.
- CI: draft. go and integration skipping, labeler and GitGuardian pass, CodeQL analyses pending at the time of reading.
UNVERIFIED:
- Linear tickets for R1.4 and R1.5 were not searched in this round.
A small Word or OpenDocument file with deeply nested XML made the router allocate far more memory than the file is long. The workbook reader already refused such files. The Word and OpenDocument readers now refuse a part nested deeper than the same limit, as too large.
Why
Ticket: AI-4157. The attribute-count gap (AI-4161) and wide table rows (AI-4323) are separate tickets and are not changed here.
How it works
nestingholds the depth rule thatlimitedTokenshad inline;limitedTokensnow uses itdepthTokensandnewDocumentDecoderwrap the six DOCX/ODT decodersTestAWordOrOpenDocumentPartNestedPastTheLimitIsRefusedBeforeItIsDecodedxmlFailure(also used byunreadable)TooLarge; any other XML error staysCorruptdepthTokenskeeps its first error;PageLimitmarks a refusal for pagesTestAPartStaysRefusedOnceItIsNestedPastTheLimit,TestAFileRefusedForItsNestingIsNotToldItHasTooManyPagesCorruptTestABrokenWordOrOpenDocumentPartIsRefusedAsCorruptTestAWordOrOpenDocumentElementMayBeNestedAsDeepAsTheLimitThe refused read allocates under six times the length of the nested part. Reading every level allocates more than fourteen times it.
Mutations and commands
Each mutant was applied alone, then
go test ./internal/knowledge/extract/ -run TestExtractSuitewas run, then the file was restored.xml.NewDecoderTestTheOpenDocumentBodyReaderRefusesABodyNestedPastTheLimit, which reads the body reader alone (in a whole read the list-style decoder refuses first)xmlFailurecall site, andunreadable, answeringCorruptxmlFailurenever answeringTooLargedepth > maxas>=, and as> max+1depthTokensnever entering, never leavingnestingnever entered, never left, or its error overwritten bylimit()Commands, in
acceleration/:go test ./internal/knowledge/...,go vet ./internal/knowledge/....🤖 Generated with Claude Code