Skip to content

Pr/tls codec fixes - #2571

Draft
clementblaudeau wants to merge 17 commits into
RustCrypto:masterfrom
cryspen:pr/tls_codec-fixes
Draft

clementblaudeau wants to merge 17 commits into
RustCrypto:masterfrom
cryspen:pr/tls_codec-fixes

Conversation

@clementblaudeau

Copy link
Copy Markdown

No description provided.

clementblaudeau and others added 17 commits December 1, 2026 15:50
On 64-bit, len_add was a plain `+`: Size sums over aliased data can
overflow (debug: panic; release: wrong length prefix). len_add is now
pub #[doc(hidden)] (API addition): derive output calls it.
With `mls`, DeserializeBytes accepted varint length prefixes of
2^30 or more (RFC 9420, 2.1.2), which the std path rejects.
…ng vectors

In debug builds, serializing a TlsVecU*/TlsByteVecU* whose content does
not fit its length field hit a debug_assert! and panicked; release
builds returned Err(InvalidVectorLength). The check right after the
assert already handles the case.
TlsVarInt::tls_deserialize read its first byte with a single `read`, so
a reader returning ErrorKind::Interrupted (documented as retryable)
made decoding of TlsVarInt, VLBytes and the types built on them fail.
It now uses `read_exact`, which retries; end of input still gives
EndOfStream.
… path

The next implicit discriminant is a number, exhausted (after the repr's
maximum) or unknown (after a path), computed by a small state machine.
After a path discriminant only the next variant needs an explicit
discriminant; implicit discriminants continue from the next literal.
The overflow and out-of-range errors of the implicit discriminant now
name the repr's maximum.
A custom io::Error payload's Debug impl is foreign code and may panic;
Error::from and the write helper now format the ErrorKind only.
The derived length guards were compiled out on 64-bit, where lengths
were assumed not to overflow; Size sums saturate there too now. A
derived SerializeBytes with a length above isize::MAX panicked in
Vec::with_capacity; it now returns InvalidVectorLength. Derived enum
SerializeBytes gets the saturated-Size guard too.
…es mismatch

In debug builds, serializing a TlsVecU*/SecretTlsVecU*/TlsSliceU* whose
elements write a different number of bytes than their
tls_serialized_len hit a debug_assert_eq! and panicked; release builds
returned Err(EncodingError). The check right after the assert already
handles the case.

This branch has not been deployed

No deployments
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.

2 participants