Merged
Conversation
vec_to_sized_array now returns Result and rejects inputs where len != N, eliminating silent truncation/zero-padding of IP addresses. Port fields are converted with u16::try_from instead of as-cast, eliminating silent port wrapping. From impls for IpV4Address/IpV6Address/IpAddr become TryFrom throughout crates/wire. Removes all cast_possible_truncation allows. Adds tests for InvalidLength and InvalidPort error paths. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This was referenced May 6, 2026
maxholman
added a commit
that referenced
this pull request
May 6, 2026
Closes 8 open dependabot alerts via transitive lockfile bumps: - rustls-webpki 0.103.9 -> 0.103.13 — CRL/URI/wildcard name-constraint handling and panic-on-malformed-CRL DoS (alerts #27 #42 #43 #47) - rand 0.8.5 -> 0.8.6 and 0.9.2 -> 0.9.4 — soundness fix for callers using a custom logger with rand::rng() (#45 #46) - h3 1.15.8 -> 1.15.11 (website) — path traversal via double-decoded %252e%252e in serveStatic and SSE event injection via unsanitized carriage return (#24 #25) No direct dependency edits; all bumps are transitive.
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.
Protobuf Boundary Safety — wire crate
Scope
crates/wire/src/helpers.rs,crates/wire/src/data.rs,crates/wire/src/socket_set.rsOut of scope
Behaviour changes beyond error propagation. No changes to callsites outside
crates/wire/.Why
Two silent data-corruption paths at the protobuf deserialisation boundary:
vec_to_sized_arraysilently truncates or zero-pads if the input lengthdoesn't match
N. A 17-byte "IPv4 address" from a malformed protobufmessage produces a wrong IP address with no error.
port as u16silently truncates a protobufu32port field. A port valueabove 65535 wraps to a wrong port with no error.
Both are suppressed today with
#[allow(clippy::cast_possible_truncation)].What
1.
vec_to_sized_array— returnResultAdd
InvalidLength { expected: usize, got: usize }toConversionErrorinhelpers.rs.Change signature:
Reject any input where
vec.len() != N.The call sites in
data.rsare currently infallibleFromimpls — changethem to
TryFrom:From<IpV4Address> for std::net::Ipv4Addr→TryFromFrom<IpV6Address> for std::net::Ipv6Addr→TryFromFrom<ip_address::IpAddress> for std::net::IpAddr→TryFromUpdate any downstream callers that used
.into()on these types to use?.2. Port truncation —
u16::try_fromAdd
InvalidPortvariant toConversionError.In
socket_set.rsanddata.rs, replace everyport as u16with:Remove:
#![allow(clippy::cast_possible_truncation)]at top ofsocket_set.rs#[allow(clippy::cast_possible_truncation)]atdata.rs:167,1783. Tests
Add
#[cfg(test)]tests inhelpers.rs:vec_to_sized_array::<4>with a 5-byte input →Err(InvalidLength)vec_to_sized_array::<4>with a 4-byte input →OkAdd test in
socket_set.rsordata.rs:70_000u32in aTryFromimpl →Err(InvalidPort)Notes
crates/protobuf/— the crate was renamed tocrates/wire/. All files are incrates/wire/.just checkmust pass after the change.