HearthSim / UnityPack

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

"struct.error: unpack requires a bytes object of length 5" problem #29

Closed vehumet closed 7 years ago

vehumet commented 7 years ago

For some unity files, unityextract prints following error,

struct.error: unpack requires a bytes object of length 5

I'm not familiar to python syntax (such as * notation), so I'm just pasting my quick fix of this problem. I refered this url: http://stackoverflow.com/questions/5773607/python-what-is-the-most-efficient-way-to-generate-padding

In utils.py,

def read(self, *args):
  return self.buf.read(*args)

to this:

def read(self, args):
  readResult = self.buf.read(args)
  if (len(readResult) < args):
    readResult = readResult .ljust(args, b'\0')
  return readResult 

I omitted * of args for just make it run with least effort ;). Sorry for that. Sorry for not uploading problematic asset file, for it's confidential one.

Thank you.

vehumet commented 7 years ago

I close this because it's duplication of https://github.com/HearthSim/UnityPack/issues/23