Skip to content

fix(prefetch): render an unset FILETIME as "-", not 1601-01-01 - #4

Merged
h4x0r merged 2 commits into
mainfrom
fix/filetime-zero-guard
Aug 5, 2026
Merged

h4x0r merged 2 commits into
mainfrom
fix/filetime-zero-guard

Conversation

@h4x0r

@h4x0r h4x0r commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Summary

prefetch4n6's filetime_to_iso had no guard for FILETIME 0, the Windows "not set" sentinel. It computed 0 / 10_000_000 - 11_644_473_600, and jiff::Timestamp::from_second accepts that value, so the function returned Some("1601-01-01T00:00:00Z") instead of None — an absent timestamp rendered as a real-looking date. Returning None lets print_record's existing - fallback engage, matching how memory-forensic's format_filetime renders the same sentinel.

Scope note — this is hardening, not a live user-visible bug

prefetch-core already breaks on the first non-positive FILETIME (core/src/lib.rs:159, Some(t) if t > 0 => push, _ => break), so ExecutionRecord.last_run_filetimes never carries a 0 for a record parsed by this workspace, and the CLI's own call site could not reach the bad rendering today. Verified empirically: a synthetic SCCA v30 with all eight last-run FILETIMEs zeroed yields last_run_times = [].

The fix still stands on its own — ExecutionRecord's fields are public, so a consumer can construct one directly, and the conversion should be correct without resting on an upstream invariant the call site does not state.

Testability seam

Added a #[cfg(test)] mod tests inside the bin rather than promoting filetime_to_iso into the library. It mirrors the convention already in forensic/src/lib.rs:196 (same #[allow(clippy::unwrap_used, clippy::expect_used)] attribute), keeps the diff minimal, and avoids adding published API surface to prefetch-forensic for a CLI-only rendering helper. The coverage gate is cargo llvm-cov --workspace --lib, so bin code sits outside the denominator either way.

TDD

Two commits, RED then GREEN.

RED (bc0f60f) — tests::unset_filetime_has_no_rendering fails:

thread 'tests::unset_filetime_has_no_rendering' panicked at forensic/src/bin/prefetch4n6.rs:86:9:
assertion `left == right` failed
  left: Some("1601-01-01T00:00:00Z")
 right: None

GREEN (935077f) — both bin tests pass.

Pre-push gate

cargo build, cargo test (17 passed, 0 failed), cargo clippy --all-targets -- -D warnings, cargo fmt --check — all clean.

Deliberately out of scope

Non-zero pre-epoch / negative FILETIMEs still convert to a pre-1970 date. memory-forensic renders those as pre-1970 (0x…); prefetch-core's t > 0 filter means they cannot arrive through the parse path here either. Left alone to keep the change minimal.

🤖 Generated with Claude Code

h4x0r and others added 2 commits August 1, 2026 16:01
FILETIME 0 is the Windows "not set" sentinel. filetime_to_iso currently
converts it to the FILETIME epoch and jiff accepts the result, so it
returns Some("1601-01-01T00:00:00Z") rather than None -- meaning
print_record's "-" fallback can never engage for an unset timestamp.

Adds a #[cfg(test)] module to the bin (mirroring the convention in
forensic/src/lib.rs) covering both the sentinel and a genuine FILETIME.

RED: tests::unset_filetime_has_no_rendering fails
  left: Some("1601-01-01T00:00:00Z")
 right: None

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
filetime_to_iso mapped the Windows "not set" sentinel (FILETIME 0) onto
the FILETIME epoch, which jiff accepts, so the CLI would print a
real-looking last-run time of 1601-01-01T00:00:00Z for a timestamp that
was never recorded. Returning None lets print_record's existing "-"
fallback engage, matching how memory-forensic's format_filetime renders
the same sentinel.

Scope note: prefetch-core already breaks on the first non-positive
FILETIME (core/src/lib.rs:159), so a record parsed by this workspace
never carries a 0 and the CLI's own call site could not reach the bad
rendering today. ExecutionRecord's fields are public, so this makes the
conversion correct on its own terms rather than resting on an upstream
invariant the call site does not state.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@h4x0r
h4x0r marked this pull request as ready for review August 5, 2026 20:27
@h4x0r
h4x0r merged commit 88b746e into main Aug 5, 2026
8 checks passed
@h4x0r
h4x0r deleted the fix/filetime-zero-guard branch August 9, 2026 15:28
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