Repository navigation
Conversation
`Document` is documented as holding "a valid DER-encoded `SEQUENCE`", and `TryFrom<Vec<u8>>` enforces that via `decode_sequence`. But `Decode for Document`, used by `Document::from_der` and `TryFrom<&[u8]>`, only peeks the header and reads that many bytes, whatever the tag. So `Document::from_der(&[0x02, 0x01, 0x00])` (an INTEGER) succeeds while `Document::try_from(vec![0x02, 0x01, 0x00])` fails, and a document built from such bytes cannot be read back from its own `to_pem` output, because `from_pem` goes through the `Vec` path. Assert the SEQUENCE tag in `Decode for Document`, as `decode_sequence` does, so all constructors agree. Adds `tests/document.rs`. Found by fuzzing der's DER -> Document -> PEM -> Document round trip.
dishmaker
reviewed
Oct 2, 2026
tarcieri
approved these changes
Oct 5, 2026
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.
Documentis documented as holding "a valid DER-encodedSEQUENCE", andTryFrom<Vec<u8>>checks that throughdecode_sequence. ButDecode for Document, whichDocument::from_derandTryFrom<&[u8]>use, only peeks the header and reads that many bytes, whatever the tag. So the result depends on which constructor is called:A document accepted this way can't be read back from its own output.
doc.to_pem(..)succeeds, andDocument::from_pemon that PEM fails because it goes throughTryFrom<Vec<u8>>. The same applies toread_der_fileandencode_msg, which also use theVecpath.Fix:
Decode for Documentasserts theSEQUENCEtag, likedecode_sequencedoes. All constructors now agree. Every in-tree caller (spki, pkcs1, pkcs8, sec1) creates documents fromSEQUENCEtypes, so none of them change.tests/document.rschecks thatfrom_der,TryFrom<&[u8]>andTryFrom<Vec<u8>>all reject INTEGER, OCTET STRING, SET and[0]inputs and all accept aSEQUENCE. It fails on master.cargo hack test --feature-powersetpasses forderon stable and on 1.85 (MSRV), as do the test suites of spki, pkcs1, pkcs8, sec1, x509-cert, pkcs12 and cms. Thethumbv7em-none-eabipowerset build succeeds, andcargo fmt --checkandcargo +1.90.0 clippy --all-features --testsare clean.Found by fuzzing
der's own round-trip promises (DER ->Document-> PEM ->Document). This PR was produced by AI agents (Claude), from the fuzzing and the fix through to this description.