Skip to content

Commit

Permalink
fix: handle potential errors in chunk decompression and parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
Mili committed Feb 27, 2025
1 parent 3f806bc commit 44db051
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pumpkin-world/src/chunk/format/anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,18 @@ impl AnvilChunkData {
// -1 for the padding/align of the *compression* byte
let bytes = &self.compressed_data[..self.length as usize - 1];

if let Some(compression) = self.compression {
let decompressed_data = compression
let chunk = if let Some(compression) = self.compression {
let decompress_bytes = compression
.decompress_data(bytes)
.expect("Failed to decompress chunk data");
.map_err(ChunkReadingError::Compression)?;

ChunkData::from_bytes(&decompressed_data, pos)
ChunkData::from_bytes(&decompress_bytes, pos)
} else {
ChunkData::from_bytes(bytes, pos)
}
.map_err(ChunkReadingError::ParsingError)
.map_err(ChunkReadingError::ParsingError)?;

Ok(chunk)
}

fn from_chunk(chunk: &ChunkData) -> Result<Self, ChunkWritingError> {
Expand Down

0 comments on commit 44db051

Please sign in to comment.