Skip to content

const-oid: reject over-u32 arcs in BER decoder instead of truncating - #2412

Merged
tarcieri merged 2 commits into
RustCrypto:masterfrom
jaideeppyne:fix/const-oid-arc-decode-overflow
Sep 4, 2026
Merged

tarcieri merged 2 commits into
RustCrypto:masterfrom
jaideeppyne:fix/const-oid-arc-decode-overflow

Conversation

@jaideeppyne

Copy link
Copy Markdown
Contributor

Arcs::try_next (used by ObjectIdentifier::from_bytes) accumulated base-128 arc digits with an unchecked result << 7, guarded only by arc_bytes > ARC_MAX_BYTES. Since a u32 arc can span up to five base-128 bytes, that guard never fires for a five-byte arc, so the final shift can push the value past u32::MAX and silently truncate it.

As a result from_bytes accepted encodings denoting arcs greater than u32::MAX and returned a wrong value instead of ArcTooBig:

  • 2A 90 80 80 80 00 (arc 2³²) decoded to 1.2.0
  • 2A 90 80 80 80 05 (arc 2³²+5) decoded to 1.2.5

This is the byte-decode counterpart of the base-10 parse overflow fixed for #1585/#1592, which only touched parser.rs.

Fix: accumulate with checked_mul/checked_add and return ArcTooBig on overflow. The largest in-range arc (u32::MAX, 2A 8F FF FF FF 7F) still decodes correctly. Adds a regression test.

The BER byte decoder (`Arcs::try_next`) accumulated base-128 arc digits
with an unchecked `result << 7` shift, guarded only by
`arc_bytes > ARC_MAX_BYTES`. Because a `u32` arc can occupy up to five
base-128 bytes, that guard never fired for a five-byte arc, so the final
shift could push the value past `u32::MAX` and silently truncate it.

As a result `ObjectIdentifier::from_bytes` accepted encodings denoting
arcs greater than `u32::MAX` and returned a wrong value rather than
`ArcTooBig`. For example `2A 90 80 80 80 00` (arc 2^32) decoded to
`1.2.0` and `2A 90 80 80 80 05` (arc 2^32+5) decoded to `1.2.5`.

Accumulate the digits with `checked_mul`/`checked_add` and return
`ArcTooBig` on overflow. The largest in-range arc (`u32::MAX`,
`2A 8F FF FF FF 7F`) still decodes correctly. Add a regression test.
Comment thread const-oid/src/arcs.rs Resolved
@tarcieri

Copy link
Copy Markdown
Member

Nice catch, thanks!

@jaideeppyne

Copy link
Copy Markdown
Contributor Author

Thanks!

@tarcieri
tarcieri merged commit 399ec59 into RustCrypto:master Sep 4, 2026
124 checks passed
paolo-de-rosa added a commit to cyberverso-net/sigillum that referenced this pull request Oct 25, 2026
## Summary

Adds ADR-0024, "Bounded decoding of untrusted input", with rules for the
library crates before their first parser is written.

- **Size limits and fuzzing.** Every public decoding entry point has a
documented, caller-configurable input size limit and a fuzz target.
- **Length walk.** An allocation-free walk, written from ITU-T X.690
(02/2021) only, checks every declared length before any allocating
decode, including DER encapsulated in OCTET STRING and BIT STRING. The
existing `check_der` of `sigillum-testpki` becomes a small public module
of `sigillum-pki` with the first library parser. A separate published
crate was rejected: another name to protect (threat S5), release
coordination, and another public API to keep stable.
- **Object identifiers.** An untrusted object identifier, in DER or in
dotted text, gives INDETERMINATE with "not supported" when it fails the
canonical syntax, the limit of 2^28 on arcs, parsing by `const-oid` or a
round-trip check. Dotted text is encoded to DER by an encoder of our
own, so the textual parser of `const-oid` 0.9.6 is never used on
untrusted input. The restriction is recorded as divergence DIV-2 (class
3 under ADR-0019).
- **Links.** Threat P2, ADR-0011, the design overview in
`architecture.md` and review checklist item 3 refer to the ADR.

The defects behind the rules are those of `der` 0.7.10 (allocation of a
declared length before checking it) and `const-oid` 0.9.6 (object
identifier arcs), all public upstream:
[RustCrypto/formats#1520](RustCrypto/formats#1520),
[#1585](RustCrypto/formats#1585),
[#1522](RustCrypto/formats#1522),
[#1592](RustCrypto/formats#1592),
[#1600](RustCrypto/formats#1600),
[#1753](RustCrypto/formats#1753),
[#2412](RustCrypto/formats#2412). The migration
to the `der` 0.8 generation (#21) checks them.

**ADR status.** ADR-0024 is accepted directly, without a *Proposed*
stage: the maintainer decided its rules in #78 and in the review of this
change. The sentence added to accepted ADR-0011 is a cross-reference
only, not a change of substance.

**Numbering.** ADR-0023 is added by #75, which merges after this pull
request.

Closes #78

## Definition of Done

- [x] Every acceptance criterion is met and covered by a test
(documentation only)
- [x] Quality gates pass, including coverage, mutation and fuzzing
thresholds where they apply ([quality
gates](https://github.com/cyberverso-net/sigillum/blob/main/docs/development/quality-gates.md))
- [x] Reviewed against the review checklist
- [x] Implemented from the specifications; no code or test data under
incompatible licences, as required by the provenance rule in
[CONTRIBUTING.md](https://github.com/cyberverso-net/sigillum/blob/main/CONTRIBUTING.md)
- [x] Documentation and rustdoc updated
- [x] ADR added for any significant decision
- [x] Intentional divergences from DSS recorded in
`docs/design/divergences.md`
- [x] Changelog fragment added under `changelog.d/`, or not needed
(reason given above)
- [x] Commits signed off
- [x] Maven dependency licences checked against
`tools/dss-oracle/README.md`, or `tools/dss-oracle/pom.xml` unchanged

## Quality report

Documentation only. All 143 links in the changed files resolve. Clauses
checked against ITU-T X.660 (07/2011), X.680 (02/2021) and X.690
(02/2021) from itu.int, and RFC 5280 from rfc-editor.org. Line
references checked against the sources of `der` 0.7.10 and `const-oid`
0.9.6.

Signed-off-by: Paolo De Rosa <paolo.de.rosa@linux.com>
@sebastienrousseau

Copy link
Copy Markdown

Could you publish a compatible const-oid 0.10.3 release containing this fix (399ec598b509a728eb13f4e82be0a2526137e81f)?

We independently reproduced the existing regression in the latest registry release, 0.10.2, while auditing rmcp 3.9.0 through sha2 0.11.1 and digest 0.11.3. The fix is already merged here, but that dependency chain still resolves the affected registry source. A patch release would let us complete the downstream source audit without a Git override or an audit exemption.

@tarcieri tarcieri mentioned this pull request Nov 10, 2026
@tarcieri

Copy link
Copy Markdown
Member

@sebastienrousseau #2530

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.

3 participants