Skip to content

soroban-spec-rust panics on invalid UTF-8 or invalid identifiers in spec entries #1765

@leighmcculloch

Description

@leighmcculloch

What version are you using?

All versions through at least 25.3.0.

What did you do?

Generated Rust bindings from a Wasm contract containing invalid UTF-8 bytes (or invalid Rust identifiers) in ScSpec entry names (function names, type names, field names).

Minimal reproduction as a test:

#[test]
#[should_panic]
fn test_invalid_utf8() {
    use stellar_xdr::curr::{ScSpecUdtStructV0, StringM, VecM};
    let spec = ScSpecUdtStructV0 {
        doc: "".try_into().unwrap(),
        lib: "".try_into().unwrap(),
        name: StringM::try_from(vec![0xff, 0xfe]).unwrap(), // invalid UTF-8
        fields: VecM::default(),
    };
    types::generate_struct(&spec); // panics
}

What did you expect to see?

The generator returns an error when spec entries contain invalid UTF-8 or names that cannot form valid Rust identifiers.

What did you see instead?

The generator panics (via unwrap() or format_ident!), crashing the tool or process.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions