Skip to content

Commit

Permalink
experimental: Add fuzzer
Browse files Browse the repository at this point in the history
  • Loading branch information
gmallios committed Dec 14, 2023
1 parent b7fe5e5 commit 9dc5996
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
3 changes: 2 additions & 1 deletion soundcore-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ dialoguer = { version = "0.10.4", features = ["fuzzy-select"] }
derive_more = { version = "0.99", features = ["from"] }

[dev-dependencies]
test_data = { path = "../test_data/" }
test_data = { path = "../test_data/" }
cargo-fuzz = "0.11.2"
4 changes: 4 additions & 0 deletions soundcore-lib/fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
corpus
artifacts
coverage
33 changes: 33 additions & 0 deletions soundcore-lib/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[package]
name = "soundcore-lib-fuzz"
version = "0.0.0"
publish = false
edition = "2021"

[package.metadata]
cargo-fuzz = true

[dependencies]
libfuzzer-sys = "0.4"

[dependencies.soundcore-lib]
path = ".."

# Prevent this from interfering with workspaces
[workspace]
members = ["."]

[profile.release]
debug = 1

[[bin]]
name = "fuzz_target_1"
path = "fuzz_targets/fuzz_target_1.rs"
test = false
doc = false

[[bin]]
name = "a3951"
path = "fuzz_targets/a3951.rs"
test = false
doc = false
7 changes: 7 additions & 0 deletions soundcore-lib/fuzz/fuzz_targets/a3951.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![no_main]
use libfuzzer_sys::fuzz_target;
use soundcore_lib::packets::ResponsePacket;

fuzz_target!(|data: &[u8]| {
let _ = ResponsePacket::from_bytes(data);
});
2 changes: 0 additions & 2 deletions soundcore-lib/src/models/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,11 @@ pub struct TwsStatus(pub bool);
)]
pub struct WearDetection(pub bool);


#[derive(
Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Default, Hash, From,
)]
pub struct TouchTone(pub bool);


#[derive(
Debug, Serialize, Deserialize, Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Default, Hash, From,
)]
Expand Down
17 changes: 15 additions & 2 deletions soundcore-lib/src/packets/response/state/a3040.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
use serde::{Serialize, Deserialize};

use crate::models::{SingleBattery, FirmwareVer, SerialNumber};
use crate::models::{SingleBattery, FirmwareVer, SerialNumber, TouchTone, WearDetection, ThreeDimensionalEffect, BassUp, LDAC, SupportTwoCnn, InEarBeep, DeviceColor, AutoPowerOff, HearingProtect, AmbientSoundNotice, PowerOnBatteryNotice};


#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Hash)]
pub struct A3040StateResponse {
pub battery: SingleBattery,
pub fw: FirmwareVer,
pub sn: SerialNumber,

pub touch_tone: TouchTone,
pub wear_detection: WearDetection,
pub three_dimensional_effect: ThreeDimensionalEffect,
pub charging_case_battery: u8, // TODO: Extract type?
pub bass_up: BassUp,
pub device_color: DeviceColor,
pub ldac: LDAC,
pub support_two_cnn: SupportTwoCnn,
pub in_ear_beep: InEarBeep,
pub prompt_language: u8, // TODO: Extract type? If == 0, then English. If == 1, then Chinese.
pub auto_power_off: AutoPowerOff,
pub hearing_protect: HearingProtect,
pub ambient_sound_notice: AmbientSoundNotice,
pub power_on_battery_notice: PowerOnBatteryNotice,
}

0 comments on commit 9dc5996

Please sign in to comment.