niftools / pyffi

PyFFI is a Python library for processing block structured files.
http://www.niftools.org/pyffi
Other
47 stars 26 forks source link

unpack requires a buffer of 2 bytes #58

Closed treymerkley closed 5 years ago

treymerkley commented 5 years ago

@niftools/pyffi-reviewers

Issue Overview

It looks like the same problem with #38. The breakage occurs using the same code as here, so it shouldn't be anything I'm doing. I'm using Apel's Morrowind sign texture as a test file.

Version Information

Pyffi Version Info

2.2.3

Platform information

Manjaro Linux, most recent stable, kernel 4.19 stable

Context

import argparse, re, os
from pyffi.formats.nif import NifFormat
for stream, data in NifFormat.walkData('/tmp/Apel Tavern Sign Retexture V1-42576-1-0'):
    try:
        # the replace call makes the doctest also pass on windows
        print("reading %s" % stream.name.replace("\\", "/"))
        data.read(stream)
    except Exception:
        print(
            "Warning: read failed due corrupt file,"
            " corrupt format description, or bug.")

Steps to Reproduce

Run the above pointing to the correct location.

.

Expected Result

A nonfailing run.

Actual Result

reading /tmp/Apel Tavern Sign Retexture V1-42576-1-0/meshes/x/furn_sign_inn_01.nif
Reading <struct 'NiTriShapeData'> failed
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/pyffi/formats/nif/__init__.py", line 1383, in read
    block.read(stream, self)
  File "/usr/lib/python3.7/site-packages/pyffi/object_models/xml/struct_.py", line 373, in read
    attr_value.read(stream, data)
  File "/usr/lib/python3.7/site-packages/pyffi/object_models/xml/array.py", line 304, in read
    elem.read(stream, data)
  File "/usr/lib/python3.7/site-packages/pyffi/object_models/xml/struct_.py", line 373, in read
    attr_value.read(stream, data)
  File "/usr/lib/python3.7/site-packages/pyffi/object_models/xml/array.py", line 304, in read
    elem.read(stream, data)
  File "/usr/lib/python3.7/site-packages/pyffi/object_models/common.py", line 167, in read
    stream.read(self._size))[0]
struct.error: unpack requires a buffer of 2 bytes
Warning: read failed due corrupt file, corrupt format description, or bug.

Possible Fix

It looks like a regression because of the way Morrowind textures work versus some of the later games. There was a point at which this worked (roughly a couple of years ago), so maybe dropping into the original code on this error occurring would cause a fix.

Similar Known Issues

38

neomonkeus commented 5 years ago

Yeah this is a known issue, the same as you have connected up to. It occurred due to bumping up the version of nif.xml for what was meant to be a stable release. The issue is with flag data, you'll see mention of it here in the first few commits here about bsuv flags - https://github.com/niftools/pyffi/compare/pyffi-2.2.3...develop

The problem is that reverting back re-introduces other issues. The problem however is in order to fix the underlying issue with the format description, i.e nif.xml, there has been a large amount of changes required to support. There is some progress being made in the branches, but it is slow enough.

If you are doing morrowind updates, I would probably go with version 2.2.2 as that won't have the issue, which should be fine for your use case.

treymerkley commented 5 years ago

fair enough, thanks! I'll go ahead and close.