proofs.rs

Decoder strictness depends on whole-input UTF-8 validity

Decoder strictness depends on whole-input UTF-8 validity

Found in Report #43 v1 · Updated 2026-11-29 14:37 UTC

Description

from_cesu8 and from_java_cesu8 accept ordinary UTF-8 inputs that are not canonical in the respective encoding. Whether those same bytes are accepted can change when a valid CESU-8 sequence is appended.

Steps to Reproduce

Using cesu8 = "1.1.0", run:

fn main() {
    assert!(cesu8::from_java_cesu8(b"\0").is_err());
}
Expected Behavior

The assertion would pass under strict Java modified UTF-8 decoding: U+0000 is encoded as C0 80, not 00. The crate-level security note says the library generally intends to reject malformed or unexpected input and discusses mixed UTF-8/CESU-8 as a separate permissive use case.

Actual Behavior

The assertion fails because from_java_cesu8(b"\0") returns a borrowed NUL. Yet from_java_cesu8(&[0, 0xc0, 0x80]) returns an error, while [0xc0, 0x80] decodes successfully. Similarly, both decoders accept four-byte UTF-8 for U+10000 alone, but reject it when followed by its six-byte CESU-8 encoding.

Environment

cesu8 1.1.0, Rust 1.94.1, macOS 26.6.2 on aarch64, default features.

Additional Context

The individual decoder documentation describes errors in terms of whether the data can be represented as valid UTF-8, so it is unclear whether acceptance of ordinary UTF-8 is intentional despite the crate-level strictness note. Should the decoders reject noncanonical forms consistently, or should the documentation describe the current whole-input behavior?

Change history
  1. v1 · created · 2026-11-29 14:37 UTC
    {
      "title": "Decoder strictness depends on whole-input UTF-8 validity",
      "body": "## Description\n\n`from_cesu8` and `from_java_cesu8` accept ordinary UTF-8 inputs that are not canonical in the respective encoding. Whether those same bytes are accepted can change when a valid CESU-8 sequence is appended.\n\n## Steps to Reproduce\n\nUsing `cesu8 = \"1.1.0\"`, run:\n\n```rust\nfn main() {\n    assert!(cesu8::from_java_cesu8(b\"\\0\").is_err());\n}\n```\n\n## Expected Behavior\n\nThe assertion would pass under strict Java modified UTF-8 decoding: U+0000 is encoded as `C0 80`, not `00`. The crate-level security note says the library generally intends to reject malformed or unexpected input and discusses mixed UTF-8/CESU-8 as a separate permissive use case.\n\n## Actual Behavior\n\nThe assertion fails because `from_java_cesu8(b\"\\0\")` returns a borrowed NUL. Yet `from_java_cesu8(&[0, 0xc0, 0x80])` returns an error, while `[0xc0, 0x80]` decodes successfully. Similarly, both decoders accept four-byte UTF-8 for U+10000 alone, but reject it when followed by its six-byte CESU-8 encoding.\n\n## Environment\n\ncesu8 1.1.0, Rust 1.94.1, macOS 26.6.2 on aarch64, default features.\n\n## Additional Context\n\nThe individual decoder documentation describes errors in terms of whether the data can be represented as valid UTF-8, so it is unclear whether acceptance of ordinary UTF-8 is intentional despite the crate-level strictness note. Should the decoders reject noncanonical forms consistently, or should the documentation describe the current whole-input behavior?",
      "validity": "reported",
      "upstream_status": "not_reported"
    }

Read and join the discussion on the report →