Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to parse TAG_LIST since 1.7 (didn't test with any snapshots) #73

Closed
schoentoon opened this issue Oct 26, 2013 · 11 comments
Closed

Comments

@schoentoon
Copy link

I upgraded our server from 1.6.4 to 1.7.2 yesterday and suddenly one of my scripts to print the death counters stopped working. After looking into it it turns out it suddenly fails to parse the TAG_LIST.

Example of what I did to reproduce below. Please note that the scoreboard in minecraft is in fact filled with some objectives.

>>> from nbt import *
>>> nbtfile = nbt.NBTFile("/home/schoentoon/minecraft/survival/world/data/scoreboard.dat", 'rb')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/NBT-1.3-py2.7.egg/nbt/nbt.py", line 458, in __init__
    self.parse_file()
  File "/usr/local/lib/python2.7/dist-packages/NBT-1.3-py2.7.egg/nbt/nbt.py", line 475, in parse_file
    self._parse_buffer(self.file)
  File "/usr/local/lib/python2.7/dist-packages/NBT-1.3-py2.7.egg/nbt/nbt.py", line 345, in _parse_buffer
    tag = TAGLIST[type.value](buffer=buffer)
  File "/usr/local/lib/python2.7/dist-packages/NBT-1.3-py2.7.egg/nbt/nbt.py", line 333, in __init__
    self._parse_buffer(buffer)
  File "/usr/local/lib/python2.7/dist-packages/NBT-1.3-py2.7.egg/nbt/nbt.py", line 345, in _parse_buffer
    tag = TAGLIST[type.value](buffer=buffer)
  File "/usr/local/lib/python2.7/dist-packages/NBT-1.3-py2.7.egg/nbt/nbt.py", line 265, in __init__
    raise ValueError("No type specified for list")
ValueError: No type specified for list

[edit code formatting -- MacFreek]

@macfreek
Copy link
Collaborator

Thanks for your report. Either Mojang added another type to the NBT files, or your file somehow got corrupted. If it is not too much trouble, could you email the scoreboard.dat file to me? My email address is on my Github page (http://github.com/macfreek)

@schoentoon
Copy link
Author

File certainly isn't corrupted as both minecraft and my own tool https://github.com/schoentoon/nbtcurses are able to read it. Will email you the scoreboard.dat in a bit.

@macfreek
Copy link
Collaborator

Indeed, a bug in the NBT library is a rather likely cause too. :). File received also gives the same error here. I'll have a look, hopefully tonight.

@macfreek
Copy link
Collaborator

I found the cause.Your file contains a rather odd TAG_List.

The syntax of a TAG_List is as follows:

  • 1 byte indicating that a TAG_List follows (0x09)
  • 2 bytes indicating the length n of the name of this TAG_List
  • n bytes containing the actual name of the TAG_List
  • 1 byte indicated what type of objects the list contains
  • 4 bytes indicated the number l of objects the TAG_List contains
  • ... l unnamed binary tags containing the objects in the list.

The type of the TAG_List in your file was 0x00 -- a TAG_End, and the length was also 0x00000000 -- zero length. The TAG_End is surprising, and why the NBT library raised the Exception. Normally, a List contains actual objects. So far, I've only seen TAG_Ends used to indicate the end of a TAG_Compound, never elsewhere.

I'll commit a change shortly that should add support for TAG_Lists with TAG_End objects.

>>> from nbt import *
>>> nbtfile = nbt.NBTFile("scoreboard.dat")
>>> print(nbtfile.pretty_tree())
NBTFile: {1 Entries}
{
    TAG_Compound('data'): {4 Entries}
    {
        TAG_List('Teams'): [0 _TAG_End(s)]
        TAG_List('Objectives'): [4 TAG_Compound(s)]
        {
            ....
        }
    }
}

[Edit: fix formatting of list]

@schoentoon
Copy link
Author

Wonderful, will I be able to install this fix through easy_install or will I have to do an install from source?

@macfreek
Copy link
Collaborator

Fixed in 0f3ccff

@twoolie
Copy link
Owner

twoolie commented Oct 27, 2013

@macfreek It's probably time to do a new pypy release, yes?

@macfreek
Copy link
Collaborator

You will have to install from source -- that said, we should release 1.4 of NBT. For good measure, I won't do it right after a code change, but tomorrow might be a good time.

Ideally, I should write a test for this behaviour. However, if you are willing to download the source, and test if it works fine for you, that would be good enough for me. The automated testing gives no problems either.

@macfreek
Copy link
Collaborator

@twoolie yes master, it is Time.

(Sorry, couldn't resist saying that :) )

@twoolie
Copy link
Owner

twoolie commented Oct 27, 2013

@schoentoon you can install it super easily like this:

easy_install pip
pip install git+https://github.com/twoolie/NBT@0f3ccffecb#egg=NBT

@schoentoon
Copy link
Author

@twoolie Oh thanks that's very useful. I'll install it later though, have to explore all the new biomes first ;)

Edit: Confirmed that it fixed my issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants