Skip to content

Checksum hex comparison uses OrdinalIgnoreCase, masking case-format drift between writers #1722

Description

@Widthdom

Summary

The checksum comparison in DbPathResolver.cs:323 uses StringComparison.OrdinalIgnoreCase for hex digest equality. While case-folded equality is harmless for hex, it masks a real defect: two writers in the codebase may emit the same logical hash in different cases (one uses BitConverter.ToString upper-case, another uses ToString("x2") lower-case). The comparison silently accepts the mismatch. If a future bug introduces a tampered hash that happens to differ only in case, the OrdinalIgnoreCase comparison would also accept it. More importantly, the inconsistent emit format itself is a latent contract bug.

Where

  • src/CodeIndex/Cli/DbPathResolver.cs:323 (checksum comparison)
  • All hash-emit sites elsewhere in the codebase that should be standardized

Suggested approach

(1) Audit all hash-emit sites and standardize on lowercase hex (ToString("x2")). (2) Switch the comparison to StringComparison.Ordinal. (3) Add a unit test that asserts every hash-producing helper returns lowercase. (4) Add a CI check (or schema invariant) that no persisted hash row contains uppercase letters. (5) Document the lowercase-hex convention in DEVELOPER_GUIDE.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions