Conversation
`ValueOrd for ContextSpecific<T>` (and `Application<T>`, `Private<T>`, generated by the same macro) called `self.der_cmp(other)` for EXPLICIT and `self.value_cmp(other)` for IMPLICIT. `der_cmp` compares the headers and then calls `value_cmp` on `self` again, so both arms recurse until the stack overflows whenever two fields with the same header are compared, e.g. when sorting a `SetOfVec<ContextSpecific<u8>>`. Compare the contents octets instead: the inner TLV (`der_cmp` on the value) for EXPLICIT, and the inner value (`value_cmp`) for IMPLICIT. The bug dates back to the original `*Ord` traits (RustCrypto#190) and was carried into the macro in RustCrypto#1819.
Contributor
|
Thanks! I did hit this bug, but forgot to fix after few iterations of PRs. |
tarcieri
approved these changes
Oct 2, 2026
Member
|
Hmm, this seems potentially security-critical (DoS). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ValueOrd for ContextSpecific<T>recurses into itself forever. The same impl, generated by the same macro, is used forApplication<T>andPrivate<T>:Comparing two fields with the same header overflows the stack:
Sorting a
SetOfVec<ContextSpecific<_>>hits this too.The fix compares the contents octets:
self.value.der_cmp(&other.value)(the inner TLV) for EXPLICIT, andself.value.value_cmp(&other.value)for IMPLICIT.The bug goes back to the original
*Ordtraits (#190) and was carried into the class macro in #1819.Test:
context_specific::tests::value_ordcovers both tag modes withvalue_cmp/der_cmp. On master it aborts with a stack overflow.This PR is independent of the three
SET OFordering PRs (tag octet order,UtcTime,Option::der_cmp) and merges cleanly with each.This PR was produced by AI agents (Claude) while auditing every
DerOrd/ValueOrdimpl inderafter differential fuzzing ofder/x509-certfound the tag-order issue.