Repository navigation
Conversation
The libxmlsec1-compatible library and the tree library link, load and call no C library besides the platform's C runtime. Documents are the core's trees behind opaque handles, read and changed through our own tree functions shaped like libxml2's. - core: OwnedTree, a Rust-owned mutable document over the xmloxide arena, parsed under the policy with its limits enforced while parsing, implementing the external-tree contract; XmlDocument lends it to an operation (from_owned_tree, into_owned_tree) or reads a snapshot of it (snapshot_of_external_tree); its ID table is xml:id and the IDs a caller registers - xml-sec-libxml2: the handle table (documents, nodes, attributes, namespace declarations and XPath namespace nodes, node sets) with handles from a counter that never repeats, validated on every use; the xs* tree functions and xs_tree.h with incomplete types; output and input buffers over the caller's callbacks or memory; the heap released with xsFree; the generic error channel; xs_tree_document, a clean C API document over a tree document that reads the tree at every operation - xml-sec-xmlsec1: every tree access goes through the handles; node sets, buffers and parsing are the library's own; read-only transforms read a snapshot so C callbacks still see the live tree; the headers are libxmlsec1's with xs_tree.h in place of libxml2's, generated and checked by xmlsec1-headers, and leave out the functions that read a file or install an entity loader - the C test programs use the tree functions; capi --xmlsec1 builds each against the libxmlsec1 oracle with the tree calls mapped onto libxml2 and against the library, and both print the same; the library's own round trips link nothing else, on every platform BREAKING CHANGE: xs_libxml2_document is replaced by xs_tree_document over a tree document of xs_tree.h; xmlSecParseFile, xmlSecBufferReadFile, xmlSecParsePrepareCtxt and xmlSecSetExternalEntityLoader are not offered. Part of #451
Core owned tree: - refuse a DOCTYPE the policy forbids before its internal subset is read, through the lexical scan every other parse runs, which also bounds entity expansion - report the byte ceiling as the typed policy violation - project the parsed children of an entity reference, so replacement markup is markup (XML 1.0 section 4.4.2) - normalize xml:id values before registering them and keep the normalized value (xml:id 1.0 section 4); register inserted xml:id attributes in the tree's own ID table after the edit, journaled for rollback - an ordinary attribute no longer matches a namespace declaration of the same local name; an empty namespace URI is no namespace - release the payload of freed nodes - serialize with a UTF-8 declaration, matching the bytes - parse bytes in the encoding a byte-order mark or declaration selects, UTF-16 included, and refuse parts too large together before joining them - a snapshot of an external tree refuses every mutation with ReadOnlySnapshot instead of splicing into an empty serialization Tree library: - document slots come from the never-repeating handle counter, so a freed document's slot never names a later document - an edit prunes only the name-keyed handles of its own document - a panic inside an operation returns the lent tree to its slot - a refused link or replacement leaves the node where it was - xsSearchNsByHref passes a shadowed prefix and keeps searching - a short write callback is offered the rest; no progress fails the buffer libxmlsec1 surface: - a namespace node matches an element's namespace node only with the same URI - xmlSecParseMemoryExt checks the combined size before joining the chunks Each defect carries a regression test that failed before its fix, except the chunk size check, whose effect is the allocation it avoids. Part of #451
The slot number a clean C API document keeps is never reused, so a freed document's slot is refused on every access. Part of #451
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
Codex Review Summary: ✅ CompletedThis 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. |
|
Opened from a stale branch by mistake; superseded by the PR that follows. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 742fac7714
ℹ️ 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".
| self.put_attribute(id, local_name, prefix, namespace, value); | ||
| Ok(()) |
There was a problem hiding this comment.
Update the ID index when an ID attribute changes
After parsing <r xml:id="old"/>, calling xsSetProp(root, "xml:id", "new") changes the attribute but leaves self.ids untouched: xsGetID(doc, "old") still returns the root, while xsGetID(doc, "new") returns null. Adding an xml:id through this setter likewise never registers it. This makes ID-based selection disagree with the document's current attributes and regresses the corresponding libxml2 setter behavior, which I checked against the installed library. Keep the ID index synchronized when ID attributes are added, replaced, or removed.
Useful? React with 👍 / 👎.
| self.element(element)?; | ||
| self.ids.insert(String::from(value), element); | ||
| Ok(()) |
There was a problem hiding this comment.
Reject duplicate explicit ID registrations
When callers use xsAddID to register attributes on two different elements with the same value, this unconditional insertion silently replaces the first element and reports success for both registrations. Subsequent xsGetID calls therefore select whichever element was registered last, rather than exposing the duplicate to the caller. I checked the installed libxml2 implementation: its second xmlAddID call fails and preserves the first entry. Refuse registration when the value already belongs to another live element instead of overwriting it.
Useful? React with 👍 / 👎.
| pub fn set_content(node: *mut Node, content: &str) -> Result<(), HandleError> { | ||
| handles::edit(handle_of(node), |tree, node| tree.set_text(node, content)) |
There was a problem hiding this comment.
Support attribute handles in the node-content setter
For an ordinary attribute returned by xsHasProp or an XPath attribute selection, xsNodeSetContent((xmlNodePtr)attr, "new") always fails: handles::edit resolves only Target::Node and rejects Target::Attribute with WrongKind. Thus generic node-editing code cannot update attribute values even though xsNodeGetContent supports those same handles. This contradicts the tree surface's stated libxml2-compatible semantics; I verified that the installed libxml2's xmlNodeSetContent successfully updates an attribute. Handle attribute targets separately and update their owning element's attribute.
Useful? React with 👍 / 👎.
| /// The handler a caller installed, with its context's address. | ||
| static HANDLER: Mutex<Option<(GenericErrorFunc, usize)>> = Mutex::new(None); |
There was a problem hiding this comment.
Keep generic error handlers local to the calling thread
In multithreaded applications that install a per-request error handler, this process-wide singleton lets one thread overwrite another thread's handler and context. xmlSecErrorsDefaultCallback then sends errors to the wrong request's callback, and resetting the handler on one thread disables reporting for the others. The previous implementation read libxml2's calling-thread handler through its accessor; I also verified with the installed libxml2 that two threads retain independent xmlSetGenericErrorFunc contexts. Store this handler in thread-local state rather than a process-global mutex to preserve that behavior.
Useful? React with 👍 / 👎.
Summary
mainonce feat(key-manager)!: import keys and edit trees on the shared primitives #463 merges.Changes
VerificationPolicy::check_supplied_key_verification.xmlSecCryptoAppKeyLoadMemory. MD5 and RIPEMD-160 klasses come with thelegacy-algorithmsfeature. Template functions fail when the tree refuses an attribute they were asked to set.xmlSecKeyReadBinaryFile,xmlSecSimpleKeysStoreLoad,xmlSecSimpleKeysStoreLoad_ex,xmlSecSimpleKeysStoreSave; the headers say so and point to the memory entry points. Templates are built in the document they belong to.Testing
Every C program under
crates/xml-sec-xmlsec1/tests/cprints the same as the libxmlsec1 oracle, a 1.3.13 pre-release snapshot (capi --xmlsec1); tests (with the xmlsec1 oracle and SoftHSM), clippy with all features, the alloc-only build, formatting, the header check and the clean C API check pass locally on macOS; CI runs the full matrix.Related
Closes #458
Part of #451