Skip to content

Audit 2026-10-14: Recycle Bin mode could delete permanently; wrong-target, cloud-file and long-path fixes - #1

Merged
0langa merged 7 commits into
mainfrom
audit/2026-10-14
Oct 14, 2026
Merged

0langa merged 7 commits into
mainfrom
audit/2026-10-14

Conversation

@0langa

@0langa 0langa commented Oct 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

StorageMaster audit, 2026-10-14. I reviewed deletion safety first, then scanning and robustness; the fixes below are all on the deletion and cloud-file side. Each fix below was reproduced on the original code before it was changed, except the long-path fix, which this machine's settings hide (see below).

  1. Data-loss bug: Recycle Bin mode could delete files permanently.
    • FileDeleter drove IFileOperation with FOF_NOCONFIRMATION. That flag also answers the shell's own "this cannot be recycled, delete it permanently?" prompt with yes. It applies to network shares, many removable drives, items larger than the bin's maximum size, and drives where the bin is turned off. Such an item was destroyed, and the app said it was "moved to the Recycle Bin (recoverable)".
    • The shell makes this decision for a whole batch. A batch of one local temp file and one file reached through \\localhost\C$ deleted both permanently: the Recycle Bin item count was unchanged and both outcomes said success. Cleanup, Smart Cleaner, duplicates and scheduled cleanup all use this path, with batches of up to 512 items.
  2. Wrong-target deletion: names ending in a space or a dot. Path.GetFullPath, and Win32 path resolution generally, trims those characters. A request for …\victim. therefore deleted the unselected sibling …\victim and reported success. Reproduced for victim., victim , victim. . and sub.\victim.
  3. Online-only OneDrive files.
    • Duplicate detection read them, which downloads them. A duplicate run over a synced folder could pull the cloud library onto the disk being cleaned.
    • "Large old files" offered them as reclaimable space. Deleting one freed nothing and removed the cloud copy.
  4. Long paths on default Windows installs (long-path support off). The no-follow guards called CreateFileW with plain paths. Windows answered "not found" beyond 260 characters, and the guards read that as "already deleted". A permanent delete of such a folder reported success while nothing was deleted.

Changes

Deletion safety

  • fix(delete): Recycle Bin mode no longer deletes permanently.
    • Every recycled item carries a per-item IFileOperationProgressSink (RecycleOnlyProgressSink). PreDeleteItem sets TSF_DELETE_RECYCLE_IF_POSSIBLE only when the item is headed for the bin. Without that flag, the sink returns E_ABORT, which stops the operation before anything is touched. This is the same check Electron uses for shell.trashItem.
    • After a stopped batch, items already recycled are reported as recycled. The rest are retried one by one, where the shell judges each item alone. A refusal there is final, and the item is reported as "Not deleted: Windows cannot move this item to the Recycle Bin here (…)".
    • A one-item recycle is now existence-checked the same way a batch was.
  • fix(delete): refuse names ending in a space or a dot, for every method. \\?\ paths are exact and still pass.
  • fix(paths): raw CreateFileW calls use the \\?\ form for paths of 248 characters or more (DirectoryTraversalInterop.ToWin32Path). Short paths are unchanged. This covers the delete guards, NoFollowFileEnumerator and the bulk identity read.
  • test(delete): pins batch outcomes when the shell skips a locked file. With the sink attached, the shell flags such a batch as aborted.

Scanning and cloud files

  • fix(cloud):
    • The duplicate candidate query skips files with FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS or FILE_ATTRIBUTE_OFFLINE, which the scanner already records. Pinned or locally available cloud files are still compared.
    • "Large old files" skips these files too.

Tests and CI

  • test: one ffmpeg test empties the process-wide PATH while other classes run in parallel. That made ExternalProcessRunnerTests (powershell.exe started by name) fail at random with "file not found"; seen locally. That class now runs in its own non-parallel collection.

Docs

  • docs: CODEMAP, V2_PLAN and archive/README still pointed at files removed in 580bd52 (docs/public/ROADMAP.md, the archived AIprojectcontext pack). README links and product files were not affected; every relative Markdown link resolves.
  • CHANGELOG [Unreleased], ARCHITECTURE.md and SAFETY_RECOVERY.md describe the new Recycle Bin behaviour.

Verification

  • Every ci.yml step run locally in the worktree on the final tree:
    • restore
    • cargo fmt --check, cargo clippy --all-targets --all-features -D warnings, cargo test, cargo build --release
    • the installer-script lint
    • dotnet format --verify-no-changes
    • dotnet build -c Release (0 errors; the only warnings are the ImageSharp advisories below)
    • dotnet test with STORAGEMASTER_REQUIRE_TURBO_SCANNER=true: 567 passed, 1 intentional skip (550 + 1 skip at the start)
  • Reproductions on the original code:
    • RecycleBinGuardTests: 3 tests fail on the original code with the file destroyed. They use the loopback admin share as a location without a Recycle Bin, so no system setting is changed, and return early where the share is unavailable.
    • DeleteAsync_NameEndingInDotOrSpace_DoesNotDeleteTheTrimmedSibling: 5 cases fail, 4 of them with the sibling deleted.
    • The placeholder tests fail on the original code.
  • Checked by hand with SHQueryRecycleBin counts:
    • original code: the mixed batch left the bin count unchanged (both files destroyed)
    • fixed code: count +1 (the local file is in the bin) and the network file is untouched
  • Long paths: this machine has LongPathsEnabled=1, so the failure cannot be reproduced without changing a system setting. The tests pin the path conversion and an end-to-end delete and enumeration of a 300-character tree.
  • GitHub Actions CI on this PR: build-and-test green on every push, including the final commit (bbc1b43).

Deliberately left alone

  • ImageSharp advisories (dotnet list package --vulnerable).

    • Facts: SixLabors.ImageSharp 3.1.12 has 3 high and 2 moderate advisories, published 2026-10-07. They are fixed only in 4.1.2; no 3.1.x patch exists. 4.x refuses to build without a Six Labors license key ("No Six Labors license found"). The license text itself is unchanged.
    • Exposure: the high ones are in features the app does not use (TIFF CCITT encoders, HistogramEqualization). The two moderate ones can be reached when duplicate image analysis decodes a crafted image: an ICC CLUT allocation, and a BigTIFF loop (.tif is a supported extension).
    • I reverted the bump: this needs your decision (question 1).
  • Default deletion behaviour is unchanged. Recycle Bin is still the default, and nothing new is offered. Items Windows cannot recycle are refused, not silently made permanent.

  • Size accounting:

    • folder totals use logical size
    • hard links count once per link (WinSxS is full of them)
    • online-only cloud files count at full size

    Changing any of this is a product decision (question 3).

  • The Duplicates page does not say why a selected file was not deleted (changed since analysis, locked, or now "Recycle Bin unavailable"). The status line shows a lower count and the file stays listed. A proper fix needs new strings in all three languages and UI work I could not verify visually, so it is left as a follow-up.

  • Cancel in the shell's progress dialog during a recycle batch cannot be told apart from a skipped locked file: both return S_OK with "aborted". So the remaining items are still retried individually, as before.

  • ExternalProcessRunnerTests.RunAsync_Cancellation_KillsProcessBeforeDelayedMutation exceeded its 8 s bound once (10.6 s) during a full run on a heavily loaded machine. It passed on every rerun, so its timeout is unchanged.

  • Robustness: reviewed, left as is. Unhandled-exception logging (logs/startup-errors.log) and settings persistence (one SQLite row with transactional updates) looked sound. The elevation and elevated-scan worker code paths were not reviewed in depth.

  • Duplicate finder and the last copy: no issue found.

    • The keeper is re-hashed and locked against writes and deletes for the whole group.
    • Each member is re-verified against it live.
    • Hard links are collapsed by file identity.
    • Fuzzy clusters never share a file.
  • Final path-based API boundary. Recycle and single-file deletes still cross one path-based Windows API boundary after the snapshot check. This is already documented in SAFETY_RECOVERY.md.

Open questions for you

  1. ImageSharp: get a Six Labors license key and move to 4.1.2, accept the residual risk, or limit exposure in code (for example drop .tif/.tiff from image duplicate detection)?
  2. Network shares in Recycle Bin mode: items Windows cannot recycle are now refused with a message. Do you want a follow-up "delete these permanently?" step, or is refusal the right default?
  3. Size accounting: should folder totals move to allocated size, and/or count each hard-linked file once?
  4. Online-only files: duplicate detection now always skips them. Should there be an opt-in to include them, accepting the download?

Running the tests sends a few tiny temp files to the Recycle Bin of the machine running them, as the existing batch tests already did. They are named storagemaster-test-recycle-* and smhard_batch_*.

🤖 Generated with Claude Code

0langa and others added 6 commits October 14, 2026 02:55
IFileOperation was driven with FOF_NOCONFIRMATION, which also answers the
shell's own "this cannot be recycled, delete it permanently?" question with
yes. Windows has no Recycle Bin on network shares and many removable drives,
and will not recycle an item larger than the bin's maximum size or on a drive
whose bin is turned off. Such an item was destroyed, and the deleter reported
it as moved to the Recycle Bin.

The shell makes that decision for a whole batch. Reproduced on this machine:
a two-item Recycle Bin batch of one local temp file and one file reached
through \\localhost\C$ deleted both permanently. The local file never reached
the bin and both outcomes said success. Every cleanup, Smart Cleaner and
duplicate path that offers "Recycle Bin (recoverable)" goes through it, and a
batch is up to 512 items.

Each recycled item now carries a per-item IFileOperationProgressSink.
PreDeleteItem carries TSF_DELETE_RECYCLE_IF_POSSIBLE only when the item is
headed for the bin; without it the sink returns E_ABORT, which stops the item
and everything still pending before anything is deleted. This is the check
Electron uses for shell.trashItem. After a stopped batch, items already
recycled are reported as recycled and the rest are retried one by one, where
the shell judges each item alone and a refusal is final: "Not deleted",
with the reason. A one-item recycle is now existence-checked like a batch.

RecycleBinGuardTests use the loopback admin share as a location without a
Recycle Bin, so no system setting is touched, and return early where the
share is unavailable. Three of them fail on the previous code with the file
destroyed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
VideoPHashStrategy_IsAvailable_TracksLatestSettingsValue empties the
process-wide PATH. xUnit runs test classes in parallel, so
ExternalProcessRunnerTests, which starts powershell.exe by name, failed at
random with "file not found" (seen locally in a full run). powershell.exe is
not in System32, so only PATH finds it. The class now runs in its own
non-parallel collection, the same way LocalizationCatalogTests isolates the
process-wide language.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
580bd52 deleted docs/public/ROADMAP.md and the archived AIprojectcontext
pack, but CODEMAP.md still listed ROADMAP.md as a solution file and pointed
at the archived pack, V2_PLAN.md sent readers to ROADMAP.md for the current
plan, and archive/README.md described a pack that is no longer there. No
product file or README link was affected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TryNormalizeRequest canonicalised every request with Path.GetFullPath,
which, like Win32 path resolution and every .NET file API given a plain
path, trims trailing spaces and dots from each segment. A request for
C:\x\victim. became C:\x\victim: a different entry the user never selected.
Without an expected snapshot, which the cache, browser and Windows-component
rules do not set, the deleter removed that sibling and reported success.
Reproduced in the new test for "victim.", "victim ", "victim. ." and
"sub.\victim".

Such names exist only when created through \\?\ paths, by WSL, or by tools
from other systems. A plain path cannot address them, so the request is now
refused with an explanation for every deletion method. \\?\ paths are not
normalised and still pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cleanup


Nothing looked at FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS or
FILE_ATTRIBUTE_OFFLINE, which the scanner already records from the
enumeration buffer.

- Duplicate detection: every strategy reads content (partial hash, SHA-256,
  image decode, ffmpeg, text). Reading a OneDrive online-only placeholder
  downloads the whole file, so a duplicate run over a synced folder hydrated
  every same-size cloud file onto the disk the user was trying to clean. The
  candidate query now skips files whose content is not on the disk. Pinned
  and locally available cloud files are unaffected.
- Large old files: an online-only file has a large logical size but takes no
  local space. The rule offered it as reclaimable, and deleting it freed
  nothing while removing the cloud copy. It is now skipped.

RemoteContentAttributes holds the mask in one place. Folder totals still
count logical size; see the PR notes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
.NET prefixes long paths for its own file APIs, but the no-follow guards
call CreateFileW through P/Invoke with the string as given. Windows rejects
a plain path over MAX_PATH with ERROR_PATH_NOT_FOUND unless the machine-wide
LongPathsEnabled policy is on, and it is off by default. The guards read
"not found" as "vanished". So on a default install:

- FileDeleter's permanent recursive delete returned without deleting a long
  root folder, and the request was reported as a success
- nested long folders were skipped, and the parent delete then failed
- NoFollowFileEnumerator reported long folders and files as "not found",
  so cleanup analysis missed what was inside them

DirectoryTraversalInterop.ToWin32Path now adds \\?\ (or \\?\UNC\) from the
CreateDirectory limit upward. It is used by every raw CreateFileW call,
including the bulk identity read. Short paths are passed through unchanged.

This machine has LongPathsEnabled=1, so the failure cannot be reproduced
here without changing a system setting. The tests pin the conversion and an
end-to-end delete and enumeration of a 300-character tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the Recycle Bin guard's progress sink attached, the shell recycles
everything else and then reports a batch that skipped a locked file as
aborted. Without a sink it reports success. That sends the batch down the
retry-individually route, so this pins that items already in the bin are
still reported as recycled, not as "changed or replaced" by a per-file
retry, and that only the locked file fails. The comment that said the shell
reports success corrected to match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@0langa 0langa changed the title Audit 2026-10-14: Recycle Bin mode could delete permanently, plus safety fixes Audit 2026-10-14: Recycle Bin mode could delete permanently; wrong-target, cloud-file and long-path fixes Oct 14, 2026
@0langa

0langa commented Oct 14, 2026

Copy link
Copy Markdown
Owner Author

Second-pass review: StorageMaster PR #1 (audit/2026-10-14)

Verdict: safe to merge. I found no bug in the changes, so I pushed no commits. The points under "Remaining concerns" are judgement calls or follow-ups, not blockers.

What I checked

Recycle Bin guard (RecycleOnlyProgressSink, FileDeleter)

  • Checked the IFileOperationProgressSink vtable order and GUID, and TSF_DELETE_RECYCLE_IF_POSSIBLE = 0x80, against shobjidl_core.h. They match. The check is the same one Electron uses for shell.trashItem. The flags are unchanged: FOF_ALLOWUNDO | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOFX_RECYCLEONDELETE.
  • Batch accounting: every request still yields exactly one outcome.
    • Items the shell recycled before a stop are reported as recycled.
    • Refused items, and items still present after a stopped batch, are retried alone through DeleteAsync. That retry uses the same RecycleBin method and checks the snapshot again.
    • A refusal in that retry is final.
  • Retry as a permanent delete without consent: none found. No code path switches a refused item to Permanent. Smart Cleaner, Cleanup and Duplicates all pass the user's chosen method straight through. The only other permanent route is the existing "Delete Permanently" button on the Cleanup page. It is offered only after a dry-run preview and asks for its own confirmation.
  • TOCTOU: the decision is made in PreDeleteItem, just before the engine touches the item, so it adds no new window. The final path-based shell boundary after the snapshot check is unchanged and already documented.

Mutation test. I made PreDeleteItem always return S_OK, which disables the guard. The three \\localhost\C$ tests then fail with the file destroyed, so they really detect the bug. On this machine the loopback share is reachable, so they ran in full rather than returning early. Reverted afterwards.

Names ending in a space or a dot

  • The check runs before GetFullPath, for every method.
  • . and .. segments still reach the existing root and relative-path refusals: C:\Temp\.. and C:\. are still refused as roots.
  • Forward slashes and \\.\ paths are covered.
  • Such names can't be created through Explorer or plain Win32 paths. A file the user picked in the UI can only hit this check if its name really ends that way, so a refusal beats deleting its sibling.

Long paths

  • ToWin32Path wraps every CreateFileW call site in the three files that declare it.
  • Its callers pass paths that are already canonical: TryNormalizeRequest runs GetFullPath, and NoFollowFileEnumerator normalises its roots. Skipping normalisation under \\?\ is therefore safe.
  • UNC paths get \\?\UNC\.

Cloud placeholders

  • Both scanners store the raw attribute DWORD; the Rust one uses metadata.file_attributes().
  • The SQL filter applies to existing scan sessions as well.
  • Pinned files stay duplicate candidates.

Tests

  • Every new test that really deletes works only inside temp folders it creates: sm_recycle_guard_*, smhard_trim_*, smhard_long_*.
  • The loopback-share paths point at those same temp files.
  • I also checked the existing deleting tests: none touches anything outside temp folders. The C:\Temp\... literals go through a mocked IFileDeleter.
  • The ffmpeg CollectionDefinition(DisableParallelization = true) on the test class itself is valid in xunit 2.9.3.

Localisation. The PR adds no .resw strings, so there was nothing to check in the three languages. See concern 3.

CI, run locally in a clean worktree on bbc1b43, exactly as ci.yml: every step passes.

  • restore
  • cargo fmt --check, clippy -D warnings, cargo test (14 passed), cargo build --release
  • installer-script lint
  • dotnet format --verify-no-changes
  • Release build: 0 errors; the only warnings are the 5 known ImageSharp advisories
  • dotnet test with STORAGEMASTER_REQUIRE_TURBO_SCANNER=true: 567 passed, 1 intentional skip

Remaining concerns (not fixed; judgement calls or follow-ups)

  1. The guard tests can pass without testing anything. Three of the six RecycleBinGuardTests return early when \\localhost\C$ is unavailable, for example for a non-admin user or with the Server service off. They then show as passed, not skipped. GitHub runners and this machine have the share, so CI really runs them. Reporting them as skipped would need something like Xunit.SkippableFact, because xunit 2.x has no built-in dynamic skip.
  2. A refused batch is retried one item at a time.
    • One item in a 512-item batch that has no bin (a network path, or a file larger than the bin) makes the shell refuse the whole batch.
    • Every item is then retried as its own IFileOperation on the single STA thread: correct, but noticeably slower in that case.
    • Splitting batches up front, for example network/removable paths vs. local fixed drives, would avoid it. This is an optimisation, not a fix.
  3. Behaviour change users will notice.
    • In Recycle Bin mode, USB sticks, network shares and mapped drives now give "Not deleted: …" instead of a silent permanent delete. That's the right default (open question 2 in the PR).
    • The message is an English-only constant, like the other FileDeleter errors, so German and other UI languages see English.
    • The Duplicates page doesn't show the reason at all; the PR notes this as a follow-up.
  4. \\?\ paths ending in a dot are not verified for Recycle Bin mode.
    • They pass the new check by design. For Permanent, .NET keeps them exact.
    • In Recycle Bin mode they go through SHCreateItemFromParsingName, and I did not verify that the shell keeps them exact.
    • Nothing in the app produces \\?\ paths, so the UI can't reach this case.
  5. Pre-existing, not introduced here.
    • A permanent recursive delete of a folder still opens children whose names end in a dot or space by their trimmed short path. Trimming stays inside the deletion root, so the worst case is a failed delete, not a wrong-target delete outside it.
    • Cancel in the shell's progress dialog is still followed by per-item retries; the PR documents this.
  6. Docs. I did not review the docs and CHANGELOG changes line by line.

No commits pushed by this review; CI on bbc1b43 is green.

🤖 Generated with Claude Code

@0langa
0langa merged commit 0c21947 into main Oct 14, 2026
1 check passed
@0langa
0langa deleted the audit/2026-10-14 branch October 14, 2026 14:06
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.

1 participant