Skip to content

Commit e3d9e87

Browse files
committed
Address reviewer comment
1 parent b97a106 commit e3d9e87

7 files changed

Lines changed: 28 additions & 25 deletions

File tree

src/repr/src/adt/date.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ impl RustType<ProtoDate> for Date {
5454
}
5555

5656
fn from_proto(proto: ProtoDate) -> Result<Self, TryFromProtoError> {
57-
// Go through `from_pg_epoch` so out-of-range days are rejected
58-
// here — pushing them into a `Row` succeeds but `read_datum` would
59-
// later panic when reconstructing the date.
57+
// Go through `from_pg_epoch` so out-of-range days are rejected here.
58+
// Pushing them into a `Row` succeeds, but `read_datum` would later
59+
// panic when reconstructing the date.
6060
Date::from_pg_epoch(proto.days)
6161
.map_err(|err| TryFromProtoError::InvalidFieldError(err.to_string()))
6262
}

src/repr/src/adt/numeric.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,9 @@ pub fn twos_complement_be_to_numeric_inner<D: Dec<N>, const N: usize>(
402402
if input.is_empty() {
403403
// An empty byte string is not a valid two's-complement integer. Our own
404404
// encoder never emits one (zero is the single byte `0x00`), so this only
405-
// arises from untrusted input — e.g. an Avro `decimal` field whose
406-
// unscaled value was encoded as zero-length `bytes`. Reject it rather
407-
// than indexing `input[0]` below and panicking.
405+
// arises from untrusted input. One example is an Avro `decimal` field
406+
// whose unscaled value was encoded as zero-length `bytes`. Reject it
407+
// rather than indexing `input[0]` below and panicking.
408408
bail!("cannot parse a numeric value from an empty byte string");
409409
}
410410
let is_neg = if (input[0] & 0x80) != 0 {

src/repr/src/adt/timestamp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ impl RustType<ProtoNaiveDateTime> for CheckedTimestamp<NaiveDateTime> {
899899

900900
fn from_proto(proto: ProtoNaiveDateTime) -> Result<Self, TryFromProtoError> {
901901
// Go through `from_timestamplike` so out-of-range values are
902-
// rejected here — pushing them into a `Row` succeeds but
902+
// rejected here. Pushing them into a `Row` succeeds, but
903903
// `read_datum` would panic when reconstructing the timestamp.
904904
CheckedTimestamp::from_timestamplike(NaiveDateTime::from_proto(proto)?)
905905
.map_err(|err| TryFromProtoError::InvalidFieldError(err.to_string()))
@@ -1119,8 +1119,8 @@ mod test {
11191119
fn test_round_to_precision_leap_second_off_minute() {
11201120
// Regression: parsing a `:60` literal can leave chrono's leap-second
11211121
// representation (sub-second >= 1s) on a second other than `:59` (after
1122-
// time-zone math). Rounding such a value as the string->timestamp cast
1123-
// does must not panic. `truncate_microseconds`/`truncate_milliseconds`
1122+
// time-zone math). Rounding such a value, as the string->timestamp cast
1123+
// does, must not panic. `truncate_microseconds`/`truncate_milliseconds`
11241124
// previously rebuilt the time with `from_hms_{micro,milli}_opt`, whose
11251125
// leap sub-second range is only valid at `:59`, and unwrapped the `None`.
11261126
let leap = NaiveDate::from_ymd_opt(3, 3, 17)

src/repr/src/relation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,8 +1035,8 @@ impl RustType<ProtoRelationDesc> for RelationDesc {
10351035
Box::new(itertools::repeat_n(val, proto.names.len()))
10361036
} else {
10371037
// Reject mismatched lengths explicitly rather than panicking via
1038-
// `zip_eq` below this branch is reachable from untrusted proto
1039-
// bytes.
1038+
// `zip_eq` below, since this branch is reachable from untrusted
1039+
// proto bytes.
10401040
if proto.names.len() != proto.metadata.len() {
10411041
return Err(TryFromProtoError::InvalidFieldError(format!(
10421042
"ProtoRelationDesc: names ({}) and metadata ({}) length mismatch",

src/repr/src/row/encode.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,7 +2126,9 @@ impl RowPacker<'_> {
21262126
// Map keys must be unique and strictly ascending; iterating a
21272127
// map that violates this trips a debug_assert. A crafted
21282128
// proto can, so reject it as a decode error here instead.
2129-
if let Some(prev) = prev_key && e.key.as_str() <= prev {
2129+
if let Some(prev) = prev_key
2130+
&& e.key.as_str() <= prev
2131+
{
21302132
return Err(format!(
21312133
"dict keys must be unique and in ascending order, \
21322134
but {:?} came after {:?}",
@@ -2148,9 +2150,9 @@ impl RowPacker<'_> {
21482150
// represented as variants of ProtoDatumOther.
21492151
//
21502152
// `decPackedToNumber` (called via `Decimal::from_packed_bcd`)
2151-
// doesn't bounds-check its input and segfaults on empty bcd
2152-
// reachable from untrusted proto bytes, so we reject before
2153-
// descending into the FFI.
2153+
// doesn't bounds-check its input and segfaults on empty bcd.
2154+
// That is reachable from untrusted proto bytes, so we reject
2155+
// before descending into the FFI.
21542156
if x.bcd.is_empty() {
21552157
return Err("ProtoNumeric.bcd is empty".to_string());
21562158
}
@@ -2170,9 +2172,10 @@ impl RowPacker<'_> {
21702172
upper,
21712173
} = &**inner;
21722174

2173-
// Range bounds must not be `Datum::Null` — `push_range_with`
2174-
// panics on that invariant. Reject untrusted proto bytes
2175-
// that would push a `Null` bound before calling it.
2175+
// Range bounds must not be `Datum::Null`, because
2176+
// `push_range_with` panics on that invariant. Reject
2177+
// untrusted proto bytes that would push a `Null` bound
2178+
// before calling it.
21762179
let is_null_proto = |d: &ProtoDatum| {
21772180
matches!(
21782181
d.datum_type,
@@ -2282,7 +2285,7 @@ mod tests {
22822285
#[mz_ore::test]
22832286
fn proto_row_invalid_range_is_error() {
22842287
// A ProtoRow with a range whose bounds have inconsistent datum kinds
2285-
// (or a null/extra bound) must decode to an error, not panic — the range
2288+
// (or a null/extra bound) must decode to an error, not panic. The range
22862289
// packer used to `assert!` these invariants. Regression for the
22872290
// row_proto_roundtrip cargo-fuzz finding.
22882291
use prost::Message;
@@ -2301,7 +2304,7 @@ mod tests {
23012304
#[mz_ore::test]
23022305
fn proto_row_unordered_dict_keys_is_error() {
23032306
// A ProtoRow with a dict whose keys are duplicated or not in ascending
2304-
// order must decode to an error, not panic — iterating such a map trips
2307+
// order must decode to an error, not panic. Iterating such a map trips
23052308
// a debug_assert. Regression for the row_proto_roundtrip cargo-fuzz
23062309
// finding.
23072310
use prost::Message;

src/repr/src/strconv.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -733,9 +733,9 @@ where
733733
pub fn parse_uuid(s: &str) -> Result<Uuid, ParseError> {
734734
let trimmed = s.trim();
735735
// The `uuid` crate panics while constructing a parse error for some short,
736-
// brace-wrapped inputs (e.g. `{}`, `{\0}`) it mis-slices the input. Reject
737-
// anything that can't be a UUID before handing it to the crate: the shortest
738-
// valid form is 32 hex digits and every form is ASCII.
736+
// brace-wrapped inputs (e.g. `{}`, `{\0}`) because it mis-slices the input.
737+
// Reject anything that can't be a UUID before handing it to the crate. The
738+
// shortest valid form is 32 hex digits and every form is ASCII.
739739
if trimmed.len() < 32 || !trimmed.is_ascii() {
740740
return Err(ParseError::invalid_input_syntax("uuid", s));
741741
}

src/storage-types/src/sources/casts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,8 @@ mod tests {
820820
fn error_uuid() {
821821
// `parse_uuid` rejects anything too short to be a UUID before the
822822
// `uuid` crate runs (the crate panics building an error for some
823-
// short inputs), so the error carries no crate-specific detail
824-
// matching Postgres, whose message for `'bad'::uuid` has none.
823+
// short inputs), so the error carries no crate-specific detail.
824+
// This matches Postgres, whose message for `'bad'::uuid` has none.
825825
assert_eq!(
826826
eval_cast_err(CastFunc::CastStringToUuid, "bad"),
827827
parse_err("uuid", "bad"),

0 commit comments

Comments
 (0)