Skip to content

fix(aliases): fail profile reads instead of silently returning empty - #14

Closed
relmer wants to merge 1 commit into
masterfrom
fix/profile-read-io-guards
Closed

fix(aliases): fail profile reads instead of silently returning empty#14
relmer wants to merge 1 commit into
masterfrom
fix/profile-read-io-guards

Conversation

@relmer

@relmer relmer commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Problem

fseek/ftell/fread in ReadProfileFile were unchecked — any I/O failure returned S_OK with zero lines. The subsequent write then replaced the user's entire profile with just the generated alias block.

Fix

  • Added IProfileFileAccess seam that checks every seek, tell, and read, treating short reads as failures
  • ReadProfileFile now propagates I/O errors and clears its output on failure
  • Split byte parsing and line splitting out of ReadProfileFile for testability
  • Atomic writes via scratch file + rename
  • WriteAliasBlockToFile guarded against overwriting non-empty files with empty results
  • Reports unreadable profiles without asserting (environmental, not a bug)

Tests

9 new ProfileFileManagerTests covering read failure, caller buffer clearing, empty files, line splitting, BOM handling, UTF-16 rejection, and write failure. Read-failure tests were confirmed to fail against unfixed code.

An unchecked fseek/ftell/fread in ReadProfileFile meant any I/O failure
produced S_OK with zero lines. WriteAliasBlockToFile then appended the
alias block to that emptiness and wrote it back, replacing the user's
entire profile with just the generated block.

- Add IProfileFileAccess seam whose real implementation checks every
  seek, tell and read, and treats a short read as a failure
- ReadProfileFile now propagates I/O failures and clears its output
- Split byte parsing and line splitting out of ReadProfileFile so both
  are testable without touching the real file system
- Make profile writes atomic via a scratch file plus rename
- Guard WriteAliasBlockToFile against writing an empty result over a
  file that is non-empty on disk
- Report an unreadable profile without asserting, since that is an
  environmental failure rather than an internal bug

Adds nine ProfileFileManagerTests covering read failure, caller buffer
clearing, empty files, line splitting, BOM handling, UTF-16 rejection
and write failure. Both read-failure tests were confirmed to fail
against the unfixed code.
@relmer relmer closed this Jul 29, 2026
@relmer
relmer deleted the fix/profile-read-io-guards branch August 12, 2026 16:26
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