@@ -445,6 +445,39 @@ def test_issue_67_no_crash(self) -> None:
445445 assert isinstance (result , dict )
446446 assert "encoding" in result
447447
448+ def test_issue_367_short_two_byte_runtime_error (self ) -> None :
449+ r"""Issue #367: b'\xf9\x92' raised RuntimeError.
450+
451+ Two-byte sequences that are valid multi-byte (e.g. cp932) score
452+ above the structural confidence threshold, but statistical scoring
453+ returns no results due to insufficient data. The pipeline must
454+ fall through to the fallback instead of returning an empty list.
455+ """
456+ # The exact input from the bug report
457+ result = chardet .detect (b"\xf9 \x92 " )
458+ assert isinstance (result , dict )
459+ assert "encoding" in result
460+ assert result ["encoding" ] is not None
461+
462+ def test_issue_367_additional_two_byte_sequences (self ) -> None :
463+ """Issue #367: verify other representative two-byte sequences don't crash.
464+
465+ Samples chosen from byte ranges that form valid cp932/johab multi-byte
466+ sequences — the same structural path that triggered the original bug.
467+ """
468+ samples = [
469+ b"\x81 \x40 " , # cp932 lead byte + valid trail
470+ b"\xf0 \x80 " , # cp932 high lead byte
471+ b"\xe0 \xa0 " , # cp932 lead byte
472+ b"\x84 \x41 " , # johab lead byte
473+ b"\xd9 \xfe " , # johab high lead byte
474+ b"\xf9 \x92 " , # original report
475+ ]
476+ for data in samples :
477+ result = chardet .detect (data )
478+ assert isinstance (result , dict ), f"Failed on { data !r} "
479+ assert "encoding" in result , f"Failed on { data !r} "
480+
448481
449482# =========================================================================
450483# NULL SEPARATOR ISSUES
0 commit comments