Skip to content

Fix for Value::String to Value::Fixed resolution ignoring the size from the schema.#542

Open
KitFieldhouse wants to merge 6 commits intoapache:mainfrom
KitFieldhouse:fixedResolution
Open

Fix for Value::String to Value::Fixed resolution ignoring the size from the schema.#542
KitFieldhouse wants to merge 6 commits intoapache:mainfrom
KitFieldhouse:fixedResolution

Conversation

@KitFieldhouse
Copy link
Copy Markdown

Hey all,

I noticed that the method resolve_fixed with a Value::String will ignore the size of the Schema::Fixed and will simply accept whatever sized string is provided, even if its actually too long for the provided fixed.

This fix modifies resolve_fixed so that it checks the size of the string and rejects if its too long for the Schema::Fixed. In addition, if too short of a string is supplied, it is zero padded to the required length.

Comment thread avro/src/types.rs Outdated
Comment thread avro/src/types.rs Outdated
Comment thread avro/src/types.rs Outdated
Comment thread avro/src/types.rs
martin-g and others added 4 commits May 5, 2026 08:54
Comment thread avro/src/types.rs
Err(Details::CompareFixedSizes { size, n: s.len() }.into())
} else {
let mut bytes = s.into_bytes();
bytes.resize(size, 0);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure the padding applied here is the correct thing to do.
There is no such padding for Bytes->Fixed below. An exact match of the length with the size is required.
I think the same should be done here too. Otherwise the reader of the fixed data will have do handle the padding somehow.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I agree with that logic.

Comment thread avro/src/types.rs
Comment thread avro/tests/io.rs
r#""a""#,
Value::Fixed(1, vec![97]),
Value::Fixed(2, vec![97, 0]),
), // ASCII 'a' => one byte
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is outdated here but IMO the padding should be removed. See above.

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