Skip to content

Cap total in-scope namespace bindings - #987

Merged
dralley merged 1 commit into
tafia:masterfrom
dralley:namespace-cap
Jul 30, 2026
Merged

Cap total in-scope namespace bindings#987
dralley merged 1 commit into
tafia:masterfrom
dralley:namespace-cap

Conversation

@dralley

@dralley dralley commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Replace the per-element max_declarations_per_element limit with a total in-scope max_namespace_bindings limit (default 128). Documents in excess of this limit are likely maliciously constructed, and bounding the stack scanned by resolve_prefix prevents this vector from being used to cause DDoS via CPU exhaustion.

The check moves from push() (which counted declarations per element) into add() (which checks bindings.len() against the total limit), thereby catching both single-element and cross-element accumulation.

Renames:
TooManyDeclarations -> TooManyBindings,
max_declarations_per_element -> max_namespace_bindings,
DEFAULT_MAX_DECLARATIONS_PER_ELEMENT -> DEFAULT_MAX_NAMESPACE_BINDINGS.

closes #980

@codecov-commenter

codecov-commenter commented Jul 29, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 92.45283% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.88%. Comparing base (e00ae5c) to head (033465f).
⚠️ Report is 30 commits behind head on master.

Files with missing lines Patch % Lines
src/name.rs 92.45% 4 Missing ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #987      +/-   ##
==========================================
- Coverage   57.31%   55.88%   -1.44%     
==========================================
  Files          46       47       +1     
  Lines       18197    18337     +140     
==========================================
- Hits        10429    10247     -182     
- Misses       7768     8090     +322     
Flag Coverage Δ
unittests 55.88% <92.45%> (-1.44%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dralley
dralley force-pushed the namespace-cap branch 3 times, most recently from d26e488 to 968737d Compare July 29, 2026 19:02
@dralley
dralley marked this pull request as ready for review July 29, 2026 19:03
@dralley
dralley requested a review from Mingun July 29, 2026 19:03
@dralley

dralley commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

Replaces #981

Comment thread src/name.rs
/// almost always on the root element; 128 is significantly more than what most legitimate documents
/// would declare, while bounding both the heap allocated and the cost of prefix resolution
/// (which scans the binding stack).
pub const DEFAULT_MAX_NAMESPACE_BINDINGS: usize = 128;

@dralley dralley Jul 29, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Note: default reduced from 256 to 128. No particular reason for this other than that it felt wildly excessive, and this is still fairly high. If there's a compelling argument otherwise though, I'll change it back.

Replace the per-element `max_declarations_per_element` limit with a total
in-scope `max_namespace_bindings` limit (default 128). Documents in
excess of this limit are *likely* maliciously constructed, and bounding
the stack scanned by `resolve_prefix` prevents this vector from being
used to cause DDoS via CPU exhaustion.

The check moves from `push()` (which counted declarations per element)
into `add()` (which checks `bindings.len()` against the total limit),
thereby catching both single-element and cross-element accumulation.

Renames: TooManyDeclarations -> TooManyBindings,
max_declarations_per_element -> max_namespace_bindings,
DEFAULT_MAX_DECLARATIONS_PER_ELEMENT -> DEFAULT_MAX_NAMESPACE_BINDINGS.

closes tafia#980
Comment thread src/name.rs
Comment on lines +694 to +695
} else if namespace == RESERVED_NAMESPACE_XMLNS.1 {
// error, non-`xmlns` prefix set to xmlns uri

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Originally, I placed the comment on the line before if to keep the nice formatting of else if statement. Don't know why rustfmt does not have the ability to keep else and if on different lines to keep the indentation of conditions the same.

@dralley
dralley merged commit b0611e3 into tafia:master Jul 30, 2026
7 checks passed
@dralley
dralley deleted the namespace-cap branch July 30, 2026 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants