Skip to content

add fuzz target for azihsm_ddi_tbor_codec::RequestEncoder - #612

Draft
zimmy87 wants to merge 6 commits into
mainfrom
user/v-davidz/add_tbor_encoder_fuzz
Draft

add fuzz target for azihsm_ddi_tbor_codec::RequestEncoder#612
zimmy87 wants to merge 6 commits into
mainfrom
user/v-davidz/add_tbor_encoder_fuzz

Conversation

@zimmy87

@zimmy87 zimmy87 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI review requested due to automatic review settings July 30, 2026 00:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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-sys fuzz target that chains RequestEncoder builder calls and attempts finish().
  • 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.

Comment thread fuzz/fuzz_targets/ddi/tbor/fuzz_tbor_encoder.rs Outdated
Comment thread fuzz/Cargo.toml
Comment thread Cargo.toml Outdated
Copilot AI review requested due to automatic review settings July 31, 2026 17:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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-sys is Linux-only (it depends on LLVM libFuzzer/sanitizer support), but adding the fuzz crate as a workspace member means cargo 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_reserve changes the error surface (e.g., BufferTooSmall/DataOffsetOverflow can now be returned from buffer_reserve rather than only being discovered later). There are existing integration tests for encoder error paths; please add a regression test that exercises the new buffer_reserve failure 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)

Comment thread fuzz/fuzz_targets/common.rs
Comment thread fuzz/fuzz_targets/ddi/tbor/fuzz_tbor_request_encoder.rs
Comment thread fuzz/fuzz_targets/ddi/tbor/fuzz_tbor_response_encoder.rs
Copilot AI review requested due to automatic review settings July 31, 2026 19:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 in buf. With the new unconditional stage_range(len)? check, callers with a small buffer (large enough for header+TOC but smaller than stage_base()) can no longer encode a zero-length buffer entry, even though no staged bytes will ever be copied in finish when len == 0 (data_offset remains unchanged). This is also inconsistent with padding, which only calls stage_range when len > 0.
        // Validate that the staging area can accommodate the reserved bytes.
        let _ = self.stage_range(len)?;
        self.data_offset += len;
        self.check_offset_overflow()?;

Copilot AI review requested due to automatic review settings July 31, 2026 21:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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::arbitrary isn’t referenced in this target and will trigger an unused_imports warning when compiling the fuzz crate.
use libfuzzer_sys::arbitrary;

fuzz/fuzz_targets/ddi/tbor/fuzz_tbor_response_encoder.rs:12

  • Unused import: libfuzzer_sys::arbitrary isn’t referenced in this target and will trigger an unused_imports warning when compiling the fuzz crate.
use libfuzzer_sys::arbitrary;

fuzz/fuzz_targets/common.rs:8

  • Unused import: libfuzzer_sys::arbitrary isn’t referenced in this module and will trigger an unused_imports warning when compiling the fuzz crate.
use libfuzzer_sys::arbitrary;

Copilot AI review requested due to automatic review settings July 31, 2026 22:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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. Use std::hint::black_box to 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. Use std::hint::black_box to 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();

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