From 593c475e9808aaea1c162e9f58120df29e07f0f3 Mon Sep 17 00:00:00 2001 From: Alejandro Aguilera Date: Fri, 25 Mar 2011 17:46:52 +0100 Subject: [PATCH 1/2] Fix problem loading adjacent chunks in some maps. --- chunk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/chunk.py b/chunk.py index 63de064..28f17d8 100644 --- a/chunk.py +++ b/chunk.py @@ -52,7 +52,7 @@ def get_lvldata(world, filename, x, y, retries=2): # non existent region file doesn't mean corrupt chunk. if filename == None: - return None + raise NoSuchChunk try: d = world.load_from_region(filename, x, y) From 84988aa2f6cf45c36486f40ee5307e9bc7d00998 Mon Sep 17 00:00:00 2001 From: Aaron Griffith Date: Fri, 25 Mar 2011 19:48:55 -0400 Subject: [PATCH 2/2] 0-byte region files no longer crash the whole program --- nbt.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/nbt.py b/nbt.py index 73730a0..075335c 100644 --- a/nbt.py +++ b/nbt.py @@ -217,12 +217,16 @@ class MCRFileReader(object): # go to the correct entry in the chunk location table self._file.seek(4 * (x + y * 32)) - # 3-byte offset in 4KiB sectors - offset_sectors = self._read_24bit_int() - - # 1-byte length in 4KiB sectors, rounded up - byte = self._file.read(1) - length_sectors = struct.unpack("B", byte)[0] + try: + # 3-byte offset in 4KiB sectors + offset_sectors = self._read_24bit_int() + + # 1-byte length in 4KiB sectors, rounded up + byte = self._file.read(1) + length_sectors = struct.unpack("B", byte)[0] + except (IndexError, struct.error): + # got a problem somewhere + return None # check for empty chunks if offset_sectors == 0 or length_sectors == 0: @@ -247,8 +251,11 @@ class MCRFileReader(object): # go to the correct entry in the chunk timestamp table self._file.seek(4 * (x + y * 32) + 4096) - bytes = self._file.read(4) - timestamp = struct.unpack(">I", bytes)[0] + try: + bytes = self._file.read(4) + timestamp = struct.unpack(">I", bytes)[0] + except (IndexError, struct.error): + return 0 return timestamp