Skip to content

Inhomogeneous values of Value::List when reading chunk data #55

@gcharnock

Description

@gcharnock

When loading nbt data from a chunk, various lists of numbers such as BlockStates are returned as inhomogeneous lists of various integer sizes. This seems to cause problems when trying to save these values back and the result causes minecraft to reset the chunk.

Reading the "specification" for NBT, it seems like inhomogeneous lists shouldn't be representable as the tag that indicates the type of the values in the list is only given once for the entire list. I don't know if this is some undocumented feature or if it is what is causing the chuck resets, but it seemed weird to me.

I've attached an example of chunk nbt data that seems to have this problem.

original_bytes.nbt.txt

It's base64 encoded because github doesn't seem to want to let me upload a binary file. Decode with:

base64 -d original_bytes.nbt.txt > original_bytes.nbt

Here is code I used to check for inhomogeneous lists.

use nbt::Value;
use std::collections::HashMap;

pub fn check_value(value: &Value) {
    match value {
        Value::Byte(b) => return,
        Value::Short(s) => return,
        Value::Int(i) => return,
        Value::Long(l) => return,
        Value::Float(f) => return,
        Value::Double(d) => return,
        Value::String(s) => return,
        Value::List(l) => check_list(l),
        Value::Compound(c) => check_compound(c),
        Value::ByteArray(ba) => return,
        Value::IntArray(ia) => return,
        Value::LongArray(la) => return 
    }
}

pub fn check_compound(c: &HashMap<String, Value>) {
    for (key, value) in c.iter() {
        println!("KEY: {} => {}", key, value.tag_name());
        check_value(value);
    }
}

fn check_list(l: &Vec<Value>) {
    match l.first() {
        Some(first) => {
            let tag = first.id();
            for v in l.iter() {
                if v.id() != tag {
                    panic!("NBT lists cannot be inhomogenious");
                }
            }
        }
        None => return
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions