Skip to content

[Bug]ur2/cbor_lite: Incorrect Map validation constant and TypeError in Text encoding #914

Description

@aphrodoe

While checking the ur2/ module, I discovered two runtime bugs in the vendored cbor_lite.py implementation. These bugs have likely persisted due to zero test coverage for this module.

  1. encodeText (line 155):
    The method attempts to call bytearray.append() with a bytes object (the UTF-8 encoded string). bytearray.append() only accepts a single integer (0-255). This raises a TypeError at runtime.

  2. decodeMapSize (line 314):
    The method checks for a map tag using Tag_Major_mask (0xe0) instead of Tag_Major_map (0xa0).
    This means certain malformed CBOR maps could silently pass tag validation or correctly formed maps could fail depending on the major type bits.

Although most SeedSigner PSBT and xpub data is binary (byteStrings), any attempt to use textStrings in the UR protocol would result in a crash. More importantly, the incorrect map validation constant is a risk for the reliable parsing of complex UR structures. This doesn't really cause any issues on the emulator, but it is a latent bug.

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