add fuzz target for azihsm_ddi_tbor_codec::RequestEncoder - #612
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new cargo-fuzz target to exercise azihsm_ddi_tbor_codec::RequestEncoder with randomized sequences of TOC-builder operations, aiming to catch panics/logic errors in the TBOR request encoding surface.
Changes:
- Introduces a
libfuzzer-sysfuzz target that chainsRequestEncoderbuilder calls and attemptsfinish(). - Adds a
fuzz/Cargo package with the fuzz binary configuration and local.gitignore. - Registers
fuzz/as a workspace member.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| fuzz/fuzz_targets/ddi/tbor/fuzz_tbor_encoder.rs | New libFuzzer target that drives RequestEncoder through arbitrary operation sequences. |
| fuzz/Cargo.toml | New fuzz crate manifest defining the fuzz binary and dependencies. |
| fuzz/.gitignore | Ignores fuzz build/corpus/artifact outputs. |
| Cargo.toml | Adds fuzz/ to the workspace members list. |
…_response_encoder and add fuzz_tbor_request_view & fuzz_tbor_response_view
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Suppressed comments (2)
Cargo.toml:39
libfuzzer-sysis Linux-only (it depends on LLVM libFuzzer/sanitizer support), but adding thefuzzcrate as a workspace member meanscargo xtask precheck --clippy/CI will attempt to build & clippy it on Windows as well (and this repo runs precheck clippy on Windows). That will likely break cross-platform CI unless the fuzz package/targets are excluded from precheck or made non-building on non-Linux targets.
"fuzz",
ddi/tbor/codec/src/encode.rs:150
- New early validation in
buffer_reservechanges the error surface (e.g.,BufferTooSmall/DataOffsetOverflowcan now be returned frombuffer_reserverather than only being discovered later). There are existing integration tests for encoder error paths; please add a regression test that exercises the newbuffer_reservefailure case (e.g., reserve enough bytes to exceed the staging area) to prevent future reintroduction of the bug this change fixes.
// Validate that the staging area can accommodate the reserved bytes.
let _ = self.stage_range(len)?;
self.data_offset += len;
self.check_offset_overflow()?;
Ok(self)
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.
Suppressed comments (1)
ddi/tbor/codec/src/encode.rs:149
buffer_reserve(0)should not require the staging area to fit inbuf. With the new unconditionalstage_range(len)?check, callers with a small buffer (large enough for header+TOC but smaller thanstage_base()) can no longer encode a zero-length buffer entry, even though no staged bytes will ever be copied infinishwhenlen == 0(data_offsetremains unchanged). This is also inconsistent withpadding, which only callsstage_rangewhenlen > 0.
// Validate that the staging area can accommodate the reserved bytes.
let _ = self.stage_range(len)?;
self.data_offset += len;
self.check_offset_overflow()?;
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Suppressed comments (3)
fuzz/fuzz_targets/ddi/tbor/fuzz_tbor_request_encoder.rs:12
- Unused import:
libfuzzer_sys::arbitraryisn’t referenced in this target and will trigger anunused_importswarning when compiling the fuzz crate.
use libfuzzer_sys::arbitrary;
fuzz/fuzz_targets/ddi/tbor/fuzz_tbor_response_encoder.rs:12
- Unused import:
libfuzzer_sys::arbitraryisn’t referenced in this target and will trigger anunused_importswarning when compiling the fuzz crate.
use libfuzzer_sys::arbitrary;
fuzz/fuzz_targets/common.rs:8
- Unused import:
libfuzzer_sys::arbitraryisn’t referenced in this module and will trigger anunused_importswarning when compiling the fuzz crate.
use libfuzzer_sys::arbitrary;
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Suppressed comments (3)
ddi/tbor/codec/src/encode.rs:147
let _ = self.stage_range(len)?;is a no-op binding; calling the method directly is clearer and avoids suggesting the result is intentionally dropped for side effects.
// Validate that the staging area can accommodate the reserved bytes.
let _ = self.stage_range(len)?;
self.data_offset += len;
fuzz/fuzz_targets/ddi/tbor/fuzz_tbor_request_view.rs:26
- In fuzzing builds (typically
--release), these accessor calls can be optimized away because their results are unused and the methods are pure/#[inline], which reduces the value of the fuzz target. Usestd::hint::black_boxto ensure the code paths are actually exercised.
fuzz_target!(|data: &[u8]| {
if let Ok(view) = RequestView::parse(data) {
let _ = view.version();
let _ = view.opcode();
let _ = view.toc_count();
fuzz/fuzz_targets/ddi/tbor/fuzz_tbor_response_view.rs:28
- In fuzzing builds (typically
--release), these accessor calls can be optimized away because their results are unused and the methods are pure/#[inline], which reduces the value of the fuzz target. Usestd::hint::black_boxto ensure the code paths are actually exercised.
fuzz_target!(|data: &[u8]| {
if let Ok(view) = ResponseView::parse(data) {
let _ = view.version();
let _ = view.flags();
let _ = view.fips_approved();
let _ = view.status();
No description provided.