owengage / fastnbt

Fast serde serializer and deserializer for Minecraft's NBT and Anvil formats
MIT License
186 stars 34 forks source link

UnexpectedEof when using for_each_chunk #21

Closed kirnyaaa closed 3 years ago

kirnyaaa commented 3 years ago

The following code:

use fastanvil::Region;
use std::fs::File;

fn main() {
    let file =  File::open("./region/r.0.0.mca").unwrap();
    let mut r = Region::new(file);
    r.for_each_chunk(|x, z, data| {
        println!("{}, {}", x,  z);
    }).expect("hhh");
}

gives this error and no other output

thread 'main' panicked at 'hhh: IO(Custom { kind: UnexpectedEof, error: "failed to fill whole buffer" })', src/main.rs:9:8

I've tried with 1.15 and 1.16 region files and had no luck.

owengage commented 3 years ago

Hey there. Your code looks fine so looks like a bug. Could you potentially upload that particularly Region file somewhere so I can try to reproduce it?

kirnyaaa commented 3 years ago

region.zip

owengage commented 3 years ago

Awesome. I'll have a look when I can. :)

owengage commented 3 years ago

I've released fastanvil 0.14.1 that should fix this.

This seems to be due to one of the chunks in the region not being padded to a multiple of 4096 bytes as the wiki claims it has to be. The chunk metadata includes to proper unpadded length, so I now use that instead.