Incident Overview and Contrasting Baseline Evidence
A custom C# archive tool writing extracted entries via FileStream to a BitLocker-encrypted SSD corrupted non-text binary files—images and videos—while leaving text files untouched. After copying an archive to a new machine and enabling BitLocker with default XTS-AES encryption over used space only, an immediate post-reboot extraction reported the input archive corrupted. Reloading a backup restored archive reads, yet writing extracts directly to the encrypted SSD produced byte-level damage in media files while every diffed text file matched cleanly.
Volume encryption operates below the file system via fvevol.sys on fixed blocks or sectors and does not parse file extensions or UTF-8 versus raw byte semantics. When text survives and media fails, the divergence comes from physical and runtime differences—payload size, write cadence across NAND flash page/block programming and SSD controller write buffers, OS page-cache flushes, and how Extract() manages a shared oBytes buffer, a shared archive oFileStream, and an un-disposed CryptoStream—rather than BitLocker choosing to scramble images while sparing text.
- Clean text diffs point to size and boundary exposure, not content awareness: Text files typically stay small and compact, fitting within a single buffer cycle or OS page-cache write without crossing multi-page flash program boundaries or prolonged stream lifetimes, whereas larger media files sustain longer write bursts that expose un-flushed or reused state.
- Working flash-drive extracts isolate the target write path: Reading the archive on the encrypted SSD and writing extracted bytes to a flash drive succeeded without corruption, which rules out broken AES decryption on the read side of cryptoStream.ReadExactly and shifts suspicion onto how writes land on the SSD stack.
- Clean Explorer copies to the SSD rule out blanket volume or sector failure: Copying already-extracted files from the flash drive to the SSD via Windows Explorer succeeded, showing the SSD and fvevol.sys can store those exact files intact when written through Explorer's I/O pattern and handle timing rather than Extract()'s rapid per-file loop.
- Clean SMART telemetry and event logs prove transport completion, not logical fidelity: SSD wear/error counters and Windows event logs record bus timeouts, media faults, or driver rejections; if corrupted or stale bytes enter the write path before or during host transfer, the SSD controller still programs the NAND array cleanly and reports zero errors.
- Decryption, full AES-CBC re-encryption, and rebooting alter state rather than proving cipher causation: Turning BitLocker off, switching to AES-CBC across the entire drive including free space, and rebooting cleared volatile caches, reset driver and stream state, and changed I/O timing—meaning the symptom disappearance may reflect a reset state or altered timing rather than XTS-AES versus AES-CBC alone.
When troubleshooting intermittent storage corruption, reproducing the exact BitLocker toggle sequence first is a common choice error because full-drive encryption and decryption cycles take hours while resetting the very runtime and cache states that trigger the bug. Comparing diagnostic options by signal speed and isolation shows why testing deterministic payloads and stream/write paths beats full-volume re-encryption: full re-encryption is slow and conflates cipher changes with state resets, whereas isolated write tests with byte-level verification pinpoint where bytes diverge in minutes. If writing a deterministic binary test file through the app's FileStream path to the target drive fails while external copies pass -> isolate the application's stream lifecycle, buffer reuse, and write-flush behavior before repeating multi-hour BitLocker conversions. (Signing in to a Google Account is also handy if you want to save this investigation thread and return to it easily later.)
C# FileStream Binary Corruption on BitLocker SSD Resolved via AES-CBC Full-Drive Encryption
When a custom C# archive tool corrupts images and videos written to a BitLocker-encrypted SSD while leaving text files untouched, the temptation is to blame volume encryption for somehow inspecting file extensions. It does not. BitLocker operates at the block and sector layer below the file system; it encrypts ciphertext blocks without parsing file headers, UTF-8 encoding, or media containers. Treating "text passes, media fails" as content discrimination misreads the evidence.
The real culprit sits in how application stream state, shared buffers, OS caching and minifilter timing, or BitLocker volume transitions interact with payload size and I/O cadence. A single small text file often fits inside one buffer pass or page-cache write and finishes before background filters or stream-state quirks collide. A multi-megabyte video or image stretches write duration, crosses buffer and NAND page boundaries, and exposes subtle state or timing flaws that leave SMART counters and Windows event logs completely quiet.
Relying on clean text diffs, healthy SMART attributes, or zero event-log warnings creates false confidence. Storage controllers and OS event logs report transport completion and media health—not whether the logical bytes fed into FileStream.Write were stale, misaligned, or shifted before hitting flash. As modern NVMe SSDs, default XTS-AES encryption, and custom managed utilities become standard on new workstations, silent byte corruption can sit undetected until a recovery archive fails.
Five Diagnostic Scenarios Across C#, Storage, and BitLocker
- 1. Shared Buffer, Offset Drift, and Un-Disposed CryptoStream State: In
Extract(), a shared class-level buffer (oBytes), a shared archive stream (oFileStream), and a per-entryCryptoStreamcreated withleaveOpen: truerun across a loop withoutDispose()or explicit flushing on theCryptoStream. When an earlier post-reboot read hits corrupted or shifted archive data, stream position drift or buffered block state can alter what subsequent iterations write. Small text entries often complete within a singleMAXBUFFERiteration where boundary residuals do not compound, whereas larger media payloads span repeated loop cycles and boundary transitions—turning a stream-state or offset fault into visible media corruption while short text files pass a diff. - 2. Write Path Cadence, OS Page Cache, and Minifilter Timing: Extracting from the SSD to a flash drive succeeded, and copying from the flash drive to the SSD via Windows Explorer also succeeded, while writing directly from
Extract()to the encrypted SSD corrupted media files. Those paths differ in handle lifetime, write burst cadence, and how file-system minifilter drivers (such as antivirus scanners) and the OS page cache intercept file creation and sequential writes. Rapid per-fileFileStreamcreation and tight write loops on the local volume can collide with filter scanning or dirty-page writeback windows that Explorer's copy engine or slower removable-media transfer pacing avoids—producing altered bytes in memory or cache before commit without triggering any I/O error. - 3. SSD Controller Buffers, NAND Page Boundaries, and Silent Telemetry: A passing CrystalDiskInfo check and clean Windows event logs confirm that the NVMe/SATA transport layer completed commands without bus resets, media errors, or driver rejections; they do not prove byte-for-byte logical accuracy. Inside the SSD, host writes enter controller write buffers and DRAM or Host Memory Buffer (HMB) staging before being programmed into multi-page NAND flash blocks. Long, continuous binary writes cross more NAND page and erase-block boundaries than tiny text writes, magnifying any upstream buffer/offset error or timing race while the controller still marks the block write as physically completed.
- 4. BitLocker XTS-AES Sector Tweaks and Block Alignment: BitLocker's
fvevol.sysdriver encrypts fixed logical blocks/sectors using sector-based tweaks—under XTS-AES, each sector/tweak binds ciphertext to its logical sector position rather than chaining across blocks like classic CBC. If an application writes unaligned chunks, reuses stale buffer slices, or shifts stream offsets, the bytes reachingfvevol.sysare already wrong or differently aligned before sector encryption runs. XTS-AES does not corrupt valid data on its own, nor does it care whether bytes are ASCII text or H.264 frames, but block/sector alignment and multi-block payload size determine how visibly a byte shift breaks a file format: a stray byte in a text note may leave lines readable, whereas a shifted byte in a compressed image or video header breaks entropy decoding or container framing. - 5. Used-Space-Only vs. Full-Drive Encryption and Post-Reboot State Resets: Enabling BitLocker with XTS-AES on used space only, rebooting, and hitting immediate archive corruption—then decrypting, switching to AES-CBC across the entire drive including free space, rebooting, and seeing extractions succeed—conflates cipher/space options with a full state and timing reset. Full-drive encryption and decryption take hours, force reboots, flush volatile caches, reset driver and managed runtime state, and alter I/O timing across the volume. Claiming AES-CBC fixed the bug ignores that a full state reset and altered timing can mask an intermittent stream, cache, or filter defect during a follow-up test.
Evaluating Fixes and Choosing the Right Diagnostic Path
Comparing the available actions shows why repeating a full BitLocker toggle is the slowest and noisiest path. Full-drive decryption and re-encryption takes hours and resets runtime/cache/driver state, which can hide an intermittent bug and waste time. Testing deterministic payloads through the isolated FileStream write path takes minutes, pinpoints whether byte corruption happens inside C# before the driver or during volume writes, and avoids multi-hour encryption churn.
Optimal choice: Isolate the application's FileStream and CryptoStream write path first using fixed, deterministic binary test payloads and byte-level checksums or diffs before changing BitLocker settings again. Proper using disposal/flushing on CryptoStream and per-write buffer hygiene are mandatory engineering fixes regardless of cipher mode. This approach stops working only if the defect is strictly tied to a specific OS/driver/firmware state that only appears after an un-reset multi-hour volume conversion—in which case controlled reproduction on a test image is needed.
Typical choice errors: Developers frequently assume clean SMART/event logs rule out data corruption, or treat "works after switching cipher and rebooting" as proof that the old cipher caused the bug. Both errors come from mistaking absence of error telemetry or post-reboot timing shifts for proof of logical byte integrity.
- If a deterministic binary file written through the app's
FileStreampath fails byte verification while a standard file copy passes -> use isolated stream/buffer/dispose diagnostics and write-path logging before touching BitLocker. - If direct
FileStreamwrites of deterministic binary data fail on the encrypted SSD but succeed to a flash drive or unencrypted path -> use controlled write-cadence, minifilter, and stream-lifecycle checks on the target volume rather than re-running full-drive encryption blindly. - If you need to verify whether XTS-AES vs. AES-CBC or used-space-only vs. full-drive encryption changes behavior -> use deterministic test files with cryptographic hashes before and after each step so timing and state resets do not fool your eyes.
How Encryption Mode Changes Exposed the Root Cause
BitLocker's volume filter driver (fvevol.sys) sits below the file system and encrypts fixed sector ranges without inspecting file extensions, headers, or text versus binary encodings. When a custom C# extractor corrupts multi-megabyte media files while leaving text files intact, the cipher itself is not discriminating by content type. Instead, payload size and stream state determine exposure: small text files often complete within a single MAXBUFFER pass or short OS page-cache write before state drift or filter timing races occur, whereas larger media files sustain longer loops across repeated oBytes buffer slices, un-disposed CryptoStream lifetimes, dirty-page writeback windows, and multi-page NAND flash program boundaries.
Switching from default XTS-AES with used-space-only encryption to AES-CBC with full-drive encryption did not cure a "content-aware" cipher bug; it forced a multi-hour volume conversion, reboots, volatile page-cache flushes, storage-stack re-initialization, and altered write timing. When free space is left unencrypted in used-space-only mode, newly allocated clusters on the SSD transition through allocation metadata and write-back paths that differ from pre-existing encrypted clusters, while long conversion cycles and reboots clear residual memory/filter state and shift I/O cadence. Consequently, an intermittent upstream buffer, stream-offset, or filter/cache timing fault can stop triggering right after conversion even though SMART counters and Windows event logs stay clean because the SSD controller and OS still completed the transport commands without media or bus errors.
Why Switching Modes Changed the Symptom Without Raising Hardware or OS Errors
- State and cache reset during conversion: Multi-hour encryption or decryption plus mandatory reboots flush volatile OS page caches, tear down active handles and minifilter scan states, and reset runtime timing—impacting stale stream or cache state -> clearing residual buffers/state -> making post-reboot extractions pass even when the underlying code path still has a hazard.
- Used-space versus full-drive allocation boundaries: Encrypting used space only leaves free clusters outside active encryption tracking until later allocation and write-back, whereas full-drive conversion unifies volume-wide sector state and alters write pacing—impacting cluster allocation and filter/cache timing -> changing write burst cadence -> hiding timing-sensitive corruption during immediate post-reboot tests.
- Cipher mechanics and format fragility: Under XTS-AES, logical sector tweaks bind ciphertext to sector position, while under AES-CBC, block chaining behaves differently across block boundaries; if a shared buffer or stream offset shifts bytes before encryption, those shifted bytes are encrypted faithfully—impacting compressed video/image headers and entropy streams -> breaking bitstream decoders catastrophically while leaving plain text mostly legible.
- Telemetry blindness to logical byte errors: Healthy SMART attributes and clean event logs verify physical NAND/transport completion without bus resets or media faults—impacting host-to-controller transfer accounting -> reporting success whenever sectors commit cleanly -> leaving silent pre-commit or misaligned byte corruption completely unreported.
Comparing Remediation Paths and When Each Fails
Option 1 — Re-running full-drive AES-CBC or XTS-AES conversion cycles: Low diagnostic effectiveness and high time cost. Multi-hour conversions and reboots conflate cipher differences with cache flushes, driver reloads, and changed I/O timing, which can mask an intermittent stream or filter fault rather than prove a cipher fix.
Option 2 — Isolating deterministic binary payloads through the FileStream / CryptoStream path with byte/hash verification, explicit disposal/flushing, and per-entry buffer hygiene: This is the optimal approach because it tests the exact application write path (shared oBytes, shared oFileStream, and un-disposed CryptoStream) in minutes without hours of volume conversion, catching offset drift, stale buffer slices, or un-flushed state deterministically.
When the optimal fix stops working: Isolating application stream/buffer lifecycle will not resolve corruption if the fault originates outside the process—such as a specific OS/filter/driver state that only manifests across a full-volume conversion window, or true hardware/firmware sector corruption on the drive.
Typical choice errors and their mechanism: Engineers often treat clean SMART/event logs as proof of byte-for-byte data integrity or treat post-reencryption success as proof that XTS-AES caused the corruption. Both errors happen because hardware logs only track transport/media health and full-drive conversion resets volatile state and timing, allowing confirmation bias to misattribute a state- or size-dependent bug to cipher selection.
Selection rule: If deterministic binary writes through the application's FileStream path fail byte or hash checks while an external file copy succeeds -> isolate and fix CryptoStream disposal/flushing, buffer reuse, and write-path cadence first before repeating multi-hour BitLocker conversions; if direct FileStream binary writes pass on flash or unencrypted paths but fail only on the BitLocker SSD -> inspect write cadence, minifilter interaction, and handle lifecycle on that target volume.
Why BitLocker Is Not Inspecting Your File Extensions
When a custom C# extractor corrupts images and videos on a BitLocker volume while leaving text files untouched, the instinctive guess is that something in the storage stack treats file types differently. Volume encryption at the fvevol.sys filter driver layer does not work that way. fvevol.sys sits below the file system and above the block storage driver, encrypting and decrypting fixed logical sector ranges without parsing file headers, extensions, or byte semantics. A compressed JPEG header, an MP4 atom stream, and a plain ASCII log file all arrive at the sector layer as opaque byte sequences.
What differs in practice is how those files stress the path from application memory to non-volatile NAND flash. Small text files frequently finish within a single MAXBUFFER read/write pass and stay inside a brief OS page-cache write window before any stream-state drift, handle contention, or minifilter scan delay occurs. Multi-megabyte media files sustain longer loops across repeated oBytes buffer slices, cross multiple OS dirty-page writeback cycles, and span more SSD controller write-buffer flushes and NAND page/erase-block boundaries. Even a single shifted byte or stale buffer slice behaves differently across formats: plain text often remains legible around a small shift, whereas entropy-encoded or offset-indexed media containers break structurally the moment byte alignment changes.
Tracing the Write Path: From Extract() to NAND Flash
Looking closely at Extract() reveals several places where application state and OS buffering can interact across entries before bytes ever reach the drive:
- Shared buffer and stream lifecycle in Extract(): The method reads a per-entry IV, wraps a shared oFileStream in a new read-mode CryptoStream with leaveOpen: true, and copies pSize bytes into a fresh output FileStream using a shared oBytes buffer. Because cryptoStream is never explicitly disposed or flushed in the loop, any buffered block state or reader position on the underlying oFileStream carries a risk of state drift across entries, especially if an earlier entry encountered an error, unexpected length, or partial read before the archive was restored from backup.
- Differential I/O cadence and minifilter interception: Writing directly from Extract() to the BitLocker SSD exercises a tight user-mode loop against local page-cache dirty pages and file-system minifilter drivers (such as real-time antivirus scanners) that hook file creation and write paths. Extracting to a removable flash drive changes write throughput, cache flushing behavior, and filter paths, while copying already-extracted files via Windows Explorer uses a standard copy pipeline with different handle lifetimes and burst pacing. When a write burst collides with a minifilter scan or cache flush window without raising an I/O error, the observable result is silent corruption on the high-speed local write path.
- SSD controller staging and NAND boundaries: Host writes pass through the OS page cache and the NVMe/SATA storage stack into the SSD controller's write buffer (or DRAM/Host Memory Buffer) before charge is trapped in multi-page NAND flash cells. Larger sequential media writes cross more NAND page and erase-block boundaries over a longer duration. If bytes are already misaligned or stale in memory or cache before commit, the controller programs those altered bytes faithfully across pages and reports success.
Why Clean Logs and Post-Reboot Recovery Mislead
Healthy SMART attributes in CrystalDiskInfo and clean Windows event logs only prove that the physical transport and media layer completed commands without bus resets, media uncorrectable errors, or driver faults. A drive controller tracks electrical and protocol failures—such as read retries, ECC exhaustion, or command timeouts—not whether the byte sequence handed down by user-mode code or altered in a higher buffer matches the source archive.
Turning BitLocker off, running a full decryption, re-enabling BitLocker with AES-CBC across the entire drive including free space, and rebooting changes far more than the cipher algorithm. Multi-hour volume conversion and mandatory reboots flush volatile OS page caches, tear down active file handles and minifilter scan states, reset user-mode runtime state, and alter I/O timing. A timing-sensitive race or stale stream/cache condition can disappear immediately after a conversion and reboot even if XTS-AES was never the root cause.
Evaluating Remediation Paths and Making the Right Call
Repeatedly running full-volume encryption and decryption cycles is a slow, noisy way to diagnose a file-write bug. Each cycle takes hours, forces reboots, and resets volatile caches and driver timing, which masks intermittent stream or filter defects while leaving any underlying FileStream or CryptoStream flaw intact.
| Option | Effectiveness | Mechanism and Blind Spots |
| Isolate FileStream/CryptoStream + hash verification | Highest for code and stream state | Tests deterministic binary blobs with explicit disposal, clean buffers, and per-file hashes in minutes. Misses defects that only appear across multi-hour volume state transitions or true media/firmware faults. |
| Inspect target write cadence and minifilter behavior | High for volume-specific I/O races | Targets handle lifetime, write burst pacing, and filter hooks on the BitLocker SSD when flash and Explorer copies succeed. Does not fix internal buffer or offset bugs in Extract(). |
| Re-run full-drive BitLocker conversion | Low for root-cause isolation | High time cost and high confounding risk because cache flushes, reboots, and changed I/O timing mask intermittent faults. Only warranted if reproducing a state strictly tied to volume conversion. |
Optimal choice: Start by isolating the FileStream and CryptoStream write path with deterministic binary test payloads and cryptographic hash checks before touching BitLocker settings again. Explicit stream disposal and per-entry buffer isolation give fast, repeatable proof of whether corruption originates in stream/buffer handling rather than volume encryption.
When the optimal choice stops working: Deterministic hash checks on isolated writes will not catch a defect that only manifests during specific OS filter/driver states across long-running volume conversions or physical NAND/controller faults that emerge under sustained multi-gigabyte workloads.
Decision rules:
- If deterministic binary writes through the application's FileStream path fail hash verification while an external file copy passes, fix CryptoStream disposal/flushing, buffer reuse, and stream positioning first rather than running another full-volume BitLocker conversion.
- If direct FileStream binary writes succeed on a flash drive or unencrypted path but fail on the BitLocker SSD, inspect write burst cadence, output handle lifetime, and minifilter activity on that volume.
- If comparing XTS-AES against AES-CBC or used-space-only against full-drive encryption, record pre- and post-transition hashes on identical binary test files so cache flushes and reboots are not mistaken for cipher behavior.
Verification Checklist and Hardening Practices for Binary I/O
Before trusting a custom archiver on encrypted SSDs in production, run this verification and hardening sequence:
- Dispose and flush every CryptoStream per entry: Wrap each per-entry CryptoStream in a using statement or call Dispose() explicitly so final block handling and stream state never leak into the next archive entry on a shared oFileStream.
- Eliminate cross-entry stale buffer assumptions: Scope or clear buffers cleanly per operation, verify exact byte counts returned or required, and never assume an earlier clean text extraction proves multi-pass binary safety.
- Verify byte-for-byte with cryptographic hashes: Compute SHA-256 hashes on source binary files (images, videos, archives) before packing and immediately after extraction on the target BitLocker SSD, rather than relying on visual playback, text diffs, SMART health, or event logs.
- Test across sizes that cross buffer and cache boundaries: Include test files smaller than MAXBUFFER alongside multi-megabyte binary files that force repeated loop iterations, OS page-cache writebacks, and SSD controller buffer flushes.
- Audit BitLocker and filter state as controlled variables: Record cipher mode (XTS-AES vs. AES-CBC), used-space vs. full-drive coverage, reboot state, and active security/minifilter software during any test run so timing and cache resets are tracked explicitly.
