Skip to content

Commit b11b5e5

Browse files
committed
Honor bytes after case repair
Reject a case-only correction when its normalized master-seed length conflicts with an explicit --bytes selection.\n\nSecurity: the direct normalization path now applies the same caller constraint as searched candidates and does not disclose the mismatched artifact.\n\nValidated with the full CLI test module, Ruff, formatting, and mypy.
1 parent 7d4eb2a commit b11b5e5

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

‎src/codex32/cli.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,12 @@ def _correct(
562562
interpreted = _case_interpretation(value, immutable, context.profiles, None)
563563
if interpreted is not None:
564564
candidate, search_value, erased, immutable = interpreted
565+
if (
566+
candidate is not None
567+
and isinstance(byte_length, int)
568+
and len(candidate.artifact.text) != _ms_text_length(byte_length)
569+
):
570+
raise _UsageError("--bytes does not match the corrected master-seed backup length.")
565571
else:
566572
candidate = None
567573
capture_layers: list[tuple[int, int]] = []

‎tests/test_cli.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,10 +1860,14 @@ def test_correct_suggests_the_majority_case_for_mixed_case_damage() -> None:
18601860
mixed = source[:position] + source[position].upper() + source[position + 1 :]
18611861

18621862
result = _invoke(["correct"], mixed)
1863+
wrong_length = _invoke(["correct", "--bytes", "32"], mixed)
18631864

18641865
assert result.exit_code == 1
18651866
assert source in result.stderr
18661867
assert "No valid correction found" not in result.stderr
1868+
assert wrong_length.exit_code == 2
1869+
assert "--bytes does not match" in wrong_length.stderr
1870+
assert source not in wrong_length.stderr
18671871

18681872

18691873
def test_correction_hides_internal_candidate_reparse_failures() -> None:

0 commit comments

Comments
 (0)