Skip to content

fix(rust): fix several panics detected by cargo-fuzz#3483

Merged
chaokunyang merged 1 commit intoapache:mainfrom
BaldDemian:cargo-fuzz-fix
Mar 23, 2026
Merged

fix(rust): fix several panics detected by cargo-fuzz#3483
chaokunyang merged 1 commit intoapache:mainfrom
BaldDemian:cargo-fuzz-fix

Conversation

@BaldDemian
Copy link
Copy Markdown
Contributor

Why?

Fix several new panics when feeding corner-case input found by cargo-fuzz

What does this PR do?

  • In rust/README.md, the right command to run all tests seems to be cargo test --workspace. Run cargo test --features tests will get:
    Screenshot 2026-03-15 at 6 16 51 AM

  • In rust/fory-core/src/meta/type_meta.rs,

  • In rust/fory-core/src/row/bit_util.rs, use saturating_add/mul to prevent potential overflow panic. But would it be better to return error instead of saturating_add/mul ?🤔

  • In rust/fory-core/src/row/reader.rs, direct access into slice using [] may cause out-of-bounds panic.

  • In rust/fory-core/src/serializer/collection.rs, rust/fory-core/src/serializer/map.rs and rust/fory-core/src/serializer/primitive_list.rs, we should check the remaining bytes in the buffer before allocating Vec. This can also prevent OOM.

  • In rust/fory-core/src/serializer/skip.rs, generics.first().unwrap() and generics.get(1).unwrap() will panic if the size of generics is not long enough.

Related issues

N/A

AI Contribution Checklist

N/A

Does this PR introduce any user-facing change?

N/A

Benchmark

This PR only adds additional check in case of corner-case input and thus won't has major influence on the performance.


pub fn calculate_bitmap_width_in_bytes(num_fields: usize) -> usize {
((num_fields + 63) / 64) * WORD_SIZE
(num_fields.saturating_add(63) / 64).saturating_mul(WORD_SIZE)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This change behaviour, I think you should let it crash. Such crash is basically programming error

};
};
let key_byte_size = LittleEndian::read_u64(header) as usize;
let key_end = (8usize).saturating_add(key_byte_size).min(row.len());
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ditto here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

For row format, it's not used for rpc. it's mostly used in data processing cases. So we don't need to handle malicous/invalid data.

@BaldDemian BaldDemian reopened this Mar 23, 2026
@BaldDemian
Copy link
Copy Markdown
Contributor Author

Thanks for your feedback, the mentioned changes are removed.

Copy link
Copy Markdown
Collaborator

@chaokunyang chaokunyang left a comment

Choose a reason for hiding this comment

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

LGTM

@chaokunyang chaokunyang merged commit 2098849 into apache:main Mar 23, 2026
62 of 119 checks passed
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