Repository navigation
perf(xmlenc): decrypt without redundant document parses - #307
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 21 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: caa8d4249a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 908b10f06c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Element and fragment node replacement parsed the whole document twice: once with the replacement inside a validation wrapper and once for the generation to commit. The commit candidate is now the only parse, and the replacement is checked on it: - the original parent spans exactly its projected range, so every end tag of the replacement stays inside it; - every child that intersects the replaced range lies inside it, except text folded with a neighbour, whose part inside the range must end on a token boundary (no CDATA section or reference left open); - an element replacement holds exactly one element beside whitespace, comments and processing instructions. Refs #306
Document decryption parsed the retained document's serialization again to read the selected EncryptedData. The retained generation already satisfies the operation's XML policy, so its parsed view now supplies the metadata, cipher references and key-source association directly. Closes #306
An element replacement whose surrounding whitespace folds into the neighbouring text was checked on its raw bytes, so whitespace written as a character reference or a CDATA section was refused next to text while accepted elsewhere. Once its tokens are complete, the neighbours keep their decoded values, so the replacement's own text is the folded value without their known lengths; that decoded text must be whitespace. Regression test: element_replacement_reads_folded_whitespace_by_value.
A reference to an empty entity (XML 1.0 section 2.3 [9] permits an empty value) produces no node on the roxmltree backend, so its bytes were left uncovered and treated as markup escaping the replaced range. Uncovered bytes may now be whitespace or complete references and CDATA sections; anything left open still fails. Regression test: replacement_may_hold_references_that_expand_to_nothing, run on every compiled backend.
908b10f to
5d2bd31
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5d2bd31842
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The one-parse slot check reads node source ranges. With an internal DTD the roxmltree backend gives nodes expanded from a declared entity a range inside the declaration, not at the reference, so an element replacement of `<x/>&extra;` passed with two elements and `&extra;` alone was refused. When the internal DTD is allowed and the candidate has such nodes, the replacement is validated inside a wrapper instead, which recognizes expanded markup where it occurs (XML 1.0 section 4.4.2). Documents without a DTD keep the single parse: predefined and character references keep the reference's own range. Regression test: entity_expansions_count_toward_the_replacement_shape, on every compiled backend.
Summary
Document decryption parsed the whole document four times. It now parses it twice: once for the input and once for the generation it commits.
Replacement validation on one parse. Element and fragment node replacement no longer parse a wrapped validation candidate before the commit candidate. The commit candidate is checked directly:
Bytes no node covers must be whitespace or complete references and CDATA sections (an empty entity leaves no node). When an internal DTD is allowed and the candidate holds nodes expanded from a declared entity, whose ranges may point into the declaration rather than at the reference, the replacement is validated inside the previous wrapper instead; documents without a DTD always take the single parse.
This covers
XmlDocument::replace_element,XmlDocument::replace_node_with_fragmentand the XMLEnc Element/Content replacement.Metadata from the parsed view. Document decryption reads the selected
EncryptedData, its cipher references and the key-source association from the retained document's parsed view. It no longer reparses the document's serialization.Performance
Measured on
DecryptContext::decrypt_documentwith a 598 KBEncryptedData(AES-256-GCM, RSA-OAEP) that decrypts to a 448 KB Element with 16384 children (macOS, release, median of 15, same session):Behaviour notes
InvalidReplacement) instead of failing the wrapper parse, because the document as a whole can still be well-formed.Testing
cargo fmt --check.cargo clippy --workspace --all-targets --all-features -D warningson stable.check-features.shlint for the xmlenc-roxmltree, dsig-roxmltree and dom-xmloxide profiles on 1.92.src/document/replacement_tests.rs, written first and passing against the previous wrapper implementation too:Closes #306