HearthSim / UnityPack

Python deserialization library for Unity3D Asset format
https://hearthsim.info/
MIT License
720 stars 152 forks source link

Mistake? `read_cstring` error message uses `list` instead of `bytes`. #60

Closed Raijinili closed 6 years ago

Raijinili commented 6 years ago

https://github.com/HearthSim/UnityPack/blob/e0e53d280537f495ef744657005a06dea3cd0694/unitypack/utils.py#L83

Shouldn't the error message use b"".join first? As is, the value is a bunch of single-byte strings.

Possible correction:

def read_cstring(self) -> bytes:
    retlst = []
    c = self.read(1)
    while c and c != b"\0":
        retlst.append(c)
        c = self.read(1)
    ret = "".join(retlst)
    if not c:
        raise ValueError("Unterminated string: %r" % (ret))
    return ret
jleclanche commented 6 years ago

Yeah that error message is fine. And your ret = "".join(retlst) would crash because you're trying to join bytes into a string (gotta decode first).