Kriskras99 commented on code in PR #339:
URL: https://github.com/apache/avro-rs/pull/339#discussion_r2582812906
##########
avro/src/decode.rs:
##########
@@ -101,39 +102,66 @@ pub(crate) fn decode_internal<R: Read, S: Borrow<Schema>>(
}
}
}
- Schema::Decimal(DecimalSchema { ref inner, .. }) => match &**inner {
- Schema::Fixed { .. } => {
- match decode_internal(inner, names, enclosing_namespace,
reader)? {
+ Schema::Decimal(DecimalSchema { inner, .. }) => match inner {
+ InnerDecimalSchema::Fixed(fixed) => {
+ match decode_internal(
+ &Schema::Fixed(fixed.copy_only_size()),
+ names,
+ enclosing_namespace,
+ reader,
+ )? {
Value::Fixed(_, bytes) =>
Ok(Value::Decimal(Decimal::from(bytes))),
value => Err(Details::FixedValue(value).into()),
}
}
- Schema::Bytes => match decode_internal(inner, names,
enclosing_namespace, reader)? {
- Value::Bytes(bytes) =>
Ok(Value::Decimal(Decimal::from(bytes))),
- value => Err(Details::BytesValue(value).into()),
- },
- schema => Err(Details::ResolveDecimalSchema(schema.into()).into()),
+ InnerDecimalSchema::Bytes => {
+ match decode_internal(&Schema::Bytes, names,
enclosing_namespace, reader)? {
+ Value::Bytes(bytes) =>
Ok(Value::Decimal(Decimal::from(bytes))),
+ value => Err(Details::BytesValue(value).into()),
+ }
+ }
},
Schema::BigDecimal => {
match decode_internal(&Schema::Bytes, names, enclosing_namespace,
reader)? {
Value::Bytes(bytes) =>
deserialize_big_decimal(&bytes).map(Value::BigDecimal),
value => Err(Details::BytesValue(value).into()),
}
}
- Schema::Uuid => {
+ Schema::Uuid(UuidSchema::String) => {
+ let Value::String(string) =
+ decode_internal(&Schema::String, names, enclosing_namespace,
reader)?
+ else {
+ // Calling decode_internal with Schema::String can only return
a Value::String or an error
Review Comment:
Removing it for `String` doesn't cause any tests to fail. Removing it for
`Union` causes this test to fail:
https://github.com/apache/avro-rs/blob/4b8d3474da670beb731eda94995aff46b51428d0/avro/src/reader.rs#L665
This was added for
[AVRO-3240](https://issues.apache.org/jira/browse/AVRO-3240?attachmentOrder=asc)
where a user wanted to decode a datum with a newer schema that has additional
(optional) fields compared to the writer schema. This is not allowed by the
specification, and should not have been added I think as it can silently allow
truncated (corrupted) files if a schema has `Union<Null, T>` at the end of the
file.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]