Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ description = "Read-only disk image carving and file recovery"
[dependencies]
slint = { version = "=1.18.1", default-features = false, features = ["std", "backend-winit", "renderer-software", "compat-1-2", "accessibility"] }
log = "=0.4.34"
# One error type for app-level failures (updater, installer, processes); parsers keep io::Result.
anyhow = { version = "=1.0.104", default-features = false, features = ["std"] }
rfd = "=0.17.2"
serde_json = "=1.0.151"
image = { version = "=0.25.10", default-features = false, features = ["ico", "png", "bmp", "jpeg", "gif", "webp"] }
Expand Down Expand Up @@ -54,8 +56,35 @@ version = "=3.27.0"
# Compiler-enforced half of the project audit (tests/audit checks these stay on).
[lints.rust]
unsafe_op_in_unsafe_fn = "deny"
# Peak tier: compiler lints that catch dead, unclear or misused code.
unused_must_use = "deny"
unused_qualifications = "deny"
unused_lifetimes = "deny"
trivial_casts = "deny"
trivial_numeric_casts = "deny"
let_underscore_drop = "deny"
elided_lifetimes_in_paths = "deny"
meta_variable_misuse = "deny"
non_ascii_idents = "deny"
redundant_lifetimes = "deny"
unit_bindings = "deny"
missing_debug_implementations = "deny"

[lints.clippy]
# Peak tier: whole Clippy groups. A lint here is a likely bug, not taste.
correctness = { level = "deny", priority = -1 }
suspicious = { level = "deny", priority = -1 }
perf = { level = "deny", priority = -1 }
complexity = { level = "deny", priority = -1 }
style = { level = "deny", priority = -1 }
pedantic = { level = "deny", priority = -1 }
# Pedantic lints that are taste, not bugs: opted out on purpose.
must_use_candidate = "allow"
too_many_lines = "allow"
module_name_repetitions = "allow"
missing_errors_doc = "allow"
struct_excessive_bools = "allow"
similar_names = "allow"
# Panics on malformed input are a denial of service (CWE-248).
unwrap_used = "deny"
expect_used = "deny"
Expand Down Expand Up @@ -86,6 +115,53 @@ fallible_impl_from = "deny"
get_unwrap = "deny"
exit = "deny"
let_underscore_must_use = "deny"
# Peak tier, bug-catching picks from nursery and restriction.
wildcard_enum_match_arm = "deny"
match_wildcard_for_single_variants = "deny"
map_err_ignore = "deny"
let_underscore_untyped = "deny"
significant_drop_in_scrutinee = "deny"
significant_drop_tightening = "deny"
collection_is_never_read = "deny"
read_zero_byte_vec = "deny"
literal_string_with_formatting_args = "deny"
debug_assert_with_mut_call = "deny"
path_buf_push_overwrite = "deny"
suspicious_operation_groupings = "deny"
iter_over_hash_type = "deny"
mixed_read_write_in_expression = "deny"
lossy_float_literal = "deny"
float_cmp_const = "deny"
rc_mutex = "deny"
mutex_atomic = "deny"
mutex_integer = "deny"
clone_on_ref_ptr = "deny"
try_err = "deny"
verbose_file_reads = "deny"
filetype_is_file = "deny"
fn_to_numeric_cast_any = "deny"
same_name_method = "deny"
rest_pat_in_fully_bound_structs = "deny"
assertions_on_result_states = "deny"
multiple_unsafe_ops_per_block = "deny"
unnecessary_safety_comment = "deny"
unnecessary_safety_doc = "deny"
infinite_loop = "deny"
error_impl_error = "deny"
string_lit_chars_any = "deny"
suspicious_xor_used_as_pow = "deny"
redundant_clone = "deny"
needless_collect = "deny"
or_fun_call = "deny"
useless_let_if_seq = "deny"
equatable_if_let = "deny"
branches_sharing_code = "deny"
set_contains_or_insert = "deny"
while_float = "deny"
unused_peekable = "deny"
non_send_fields_in_send_ty = "deny"
trait_duplication_in_bounds = "deny"
type_repetition_in_bounds = "deny"

[profile.release]
opt-level = "z"
Expand Down
8 changes: 8 additions & 0 deletions docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ cargo test --locked
cargo clippy --locked --all-targets -- -D warnings
```

Clippy runs every lint group (including `pedantic`) at `deny`, plus selected
lints that catch likely bugs: unhandled enum variants, discarded error causes,
lock guards held across a `match`, and output that depends on hash order. An
intended exception is a scoped `#[expect(lint, reason = "...")]`. `#[allow]` is
denied, and the audit fails if a required lint is removed from `Cargo.toml`.
Also run Clippy with `--target x86_64-pc-windows-gnu`, because the Windows-only
code is not checked on Linux.

`cargo test` includes the project audit and the headless UI renders.
[TESTING.md](TESTING.md) lists every suite, the audit rules, the layout checks,
fuzzing, the opt-in hardware tests, CI and the real USB drive results.
Expand Down
19 changes: 13 additions & 6 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions src/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ fn check(cancel: &AtomicBool) -> io::Result<()> {
}
}
fn u16at(b: &[u8], p: usize) -> u64 {
crate::bytes::u16_le(b, p) as u64
u64::from(crate::bytes::u16_le(b, p))
}
fn u32at(b: &[u8], p: usize) -> u64 {
crate::bytes::u32_le(b, p) as u64
u64::from(crate::bytes::u32_le(b, p))
}
fn u64at(b: &[u8], p: usize) -> u64 {
crate::bytes::u64_le(b, p)
Expand Down Expand Up @@ -305,7 +305,8 @@ impl<R: Read + Seek> Seek for FreeSpace<'_, R> {
SeekFrom::Current(n) => i128::from(self.position) + i128::from(n),
SeekFrom::End(n) => i128::from(self.length) + i128::from(n),
};
self.position = u64::try_from(next).map_err(|_| invalid("Invalid candidate position"))?;
self.position = u64::try_from(next)
.map_err(|error| io::Error::new(io::ErrorKind::InvalidInput, error))?;
Ok(self.position)
}
}
Expand All @@ -316,7 +317,7 @@ impl<R: Read + Seek> Seek for FreeSpace<'_, R> {
/// first bytes match its type is trusted to own that space; the others stay in
/// the list as unverified and their space is still carved, so a newer deleted
/// file stored there is not hidden.
fn exclude_known_files(input: &mut (impl Read + Seek), plan: &mut Plan) -> io::Result<()> {
fn exclude_known_files(input: &mut (impl Read + Seek), plan: &mut Plan) {
let mut owned: Vec<(u64, u64)> = Vec::new();
for file in &mut plan.files {
let Some(extents) = file.extents.clone() else {
Expand Down Expand Up @@ -347,12 +348,11 @@ fn exclude_known_files(input: &mut (impl Read + Seek), plan: &mut Plan) -> io::R
}
}
if owned.is_empty() {
return Ok(());
return;
}
owned.sort_unstable();
plan.ranges = subtract(&plan.ranges, &owned);
plan.unused = plan.ranges.iter().map(|(_, length)| length).sum();
Ok(())
}
/// `ranges` with the sorted `owned` ranges cut out.
fn subtract(ranges: &[(u64, u64)], owned: &[(u64, u64)]) -> Vec<(u64, u64)> {
Expand Down Expand Up @@ -401,7 +401,7 @@ pub(crate) fn scan(
}
result => result?,
};
exclude_known_files(input, &mut plan)?;
exclude_known_files(input, &mut plan);
event(crate::Event::UnusedSpace {
bytes: plan.unused,
filesystem: plan.filesystem,
Expand Down Expand Up @@ -470,7 +470,7 @@ pub(crate) fn scan(
event(crate::Event::Found(file));
}
crate::Event::Progress(bytes) => {
event(crate::Event::Progress(scale(bytes.min(length))))
event(crate::Event::Progress(scale(bytes.min(length))));
}
crate::Event::Checking {
offset,
Expand Down
32 changes: 18 additions & 14 deletions src/allocation/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ impl Heap {
}
Some(extents)
}
pub(super) fn cluster_count(self, size: u64) -> Option<u64> {
Some(size.div_ceil(self.cluster_size).max(1))
pub(super) fn cluster_count(self, size: u64) -> u64 {
size.div_ceil(self.cluster_size).max(1)
}
}

Expand All @@ -84,15 +84,15 @@ pub(super) fn found(name: String, size: u64, extents: Vec<(u64, u64)>) -> Option

/// A name from directory data is shown and used as a file name, so it must
/// be printable and must not climb or split paths.
pub(super) fn clean_name(name: String) -> Option<String> {
let name = name.trim_end_matches([' ', '.']).to_owned();
pub(super) fn clean_name(name: &str) -> Option<String> {
let name = name.trim_end_matches([' ', '.']);
(!name.is_empty()
&& name.chars().count() <= 255
&& !name
.chars()
.any(|c| c.is_control() || matches!(c, '/' | '\\' | '\0'))
&& !matches!(name.as_str(), "." | ".."))
.then_some(name)
&& !matches!(name, "." | ".."))
.then(|| name.to_owned())
}

/// Tracks the work budget of one directory walk.
Expand Down Expand Up @@ -245,7 +245,7 @@ pub(super) fn fat_entries(data: &[u8], fat32: bool) -> Vec<FatEntry> {
(derived.is_some_and(matches) || matches(b'_')).then_some(long)
});
let name = long.or_else(|| short_name(entry, b'_'));
if let Some(name) = name.and_then(clean_name) {
if let Some(name) = name.as_deref().and_then(clean_name) {
entries.push(FatEntry::Deleted(name, size, cluster));
}
}
Expand All @@ -269,7 +269,7 @@ pub(super) fn exfat_entries(data: &[u8]) -> Vec<ExfatEntry> {
.as_chunks::<32>()
.0
.iter()
.map(|r| r.as_slice())
.map(<[u8; 32]>::as_slice)
.collect();
let mut index = 0usize;
while let Some(record) = records.get(index) {
Expand Down Expand Up @@ -329,7 +329,11 @@ pub(super) fn exfat_entries(data: &[u8]) -> Vec<ExfatEntry> {
if in_use || length == 0 || units.len() != name_length {
continue;
}
if let Some(name) = String::from_utf16(&units).ok().and_then(clean_name) {
if let Some(name) = String::from_utf16(&units)
.ok()
.as_deref()
.and_then(clean_name)
{
entries.push(ExfatEntry::Deleted(name, length, cluster, contiguous));
}
}
Expand Down Expand Up @@ -457,11 +461,11 @@ mod tests {
.wrapping_add(u32::try_from(i).unwrap().wrapping_mul(40_503));
*byte = mixed.to_le_bytes()[1];
}
let _ = fat_entries(&data, seed % 2 == 0);
let _ = exfat_entries(&data);
drop(fat_entries(&data, seed % 2 == 0));
drop(exfat_entries(&data));
}
assert!(clean_name("../x".into()).is_none());
assert!(clean_name("a\u{0}b".into()).is_none());
assert_eq!(clean_name("name. ".into()).as_deref(), Some("name"));
assert!(clean_name("../x").is_none());
assert!(clean_name("a\u{0}b").is_none());
assert_eq!(clean_name("name. ").as_deref(), Some("name"));
}
}
2 changes: 1 addition & 1 deletion src/allocation/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const INCOMPAT_INLINE_DATA: u32 = 0x8000;
const INCOMPAT_ENCRYPT: u32 = 0x10000;
const INCOMPAT_CASEFOLD: u32 = 0x20000;
/// Features that do not change where block bitmaps live or what a bit means.
/// Compression, external journal devices and META_BG descriptor placement are
/// Compression, external journal devices and `META_BG` descriptor placement are
/// not in this list, so those volumes are rejected instead of misread.
const INCOMPAT_KNOWN: u32 = INCOMPAT_FILETYPE
| INCOMPAT_RECOVER
Expand Down
Loading
Loading