diff options
| author | Ubuntu <github@matdoes.dev> | 2022-11-09 18:59:03 +0000 |
|---|---|---|
| committer | Ubuntu <github@matdoes.dev> | 2022-11-09 18:59:03 +0000 |
| commit | ad8b1b7b2405b39d0f86b7adb00df7662dcd1a19 (patch) | |
| tree | cf61b61e2125e7d2ae91359c760f3a374bc24e58 | |
| parent | 8de73c336fb15aa2108d09dba833c80339ef6671 (diff) | |
| download | azalea-drasl-ad8b1b7b2405b39d0f86b7adb00df7662dcd1a19.tar.xz | |
ignore bad utf8
| -rwxr-xr-x | Cargo.lock | 1 | ||||
| -rw-r--r-- | azalea-client/src/client.rs | 3 | ||||
| -rw-r--r-- | azalea-nbt/Cargo.toml | 1 | ||||
| -rwxr-xr-x | azalea-nbt/src/decode.rs | 10 |
4 files changed, 12 insertions, 3 deletions
@@ -246,6 +246,7 @@ dependencies = [ "byteorder", "criterion", "flate2", + "log", "num-derive", "num-traits", ] diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs index ac340ede..645497f6 100644 --- a/azalea-client/src/client.rs +++ b/azalea-client/src/client.rs @@ -583,8 +583,7 @@ impl Client { client .dimension .lock() - .replace_with_packet_data(&pos, &mut Cursor::new(&p.chunk_data.data)) - .unwrap(); + .replace_with_packet_data(&pos, &mut Cursor::new(&p.chunk_data.data)); } ClientboundGamePacket::LightUpdate(_p) => { // debug!("Got light update packet {:?}", p); diff --git a/azalea-nbt/Cargo.toml b/azalea-nbt/Cargo.toml index 5e776dbe..f104e7bc 100644 --- a/azalea-nbt/Cargo.toml +++ b/azalea-nbt/Cargo.toml @@ -13,6 +13,7 @@ ahash = "^0.8.0" azalea-buf = {path = "../azalea-buf", version = "^0.3.0" } byteorder = "^1.4.3" flate2 = "^1.0.23" +log = "0.4.17" num-derive = "^0.3.3" num-traits = "^0.2.14" diff --git a/azalea-nbt/src/decode.rs b/azalea-nbt/src/decode.rs index 6937dc05..ae7cfde6 100755 --- a/azalea-nbt/src/decode.rs +++ b/azalea-nbt/src/decode.rs @@ -4,6 +4,7 @@ use ahash::AHashMap; use azalea_buf::{BufReadError, McBufReadable}; use byteorder::{ReadBytesExt, BE}; use flate2::read::{GzDecoder, ZlibDecoder}; +use log::warn; use std::io::Cursor; use std::io::{BufRead, Read}; @@ -23,7 +24,14 @@ fn read_string(stream: &mut Cursor<&[u8]>) -> Result<String, Error> { let length = stream.read_u16::<BE>()? as usize; let buf = read_bytes(stream, length)?; - Ok(std::str::from_utf8(buf)?.to_string()) + + Ok(if let Ok(string) = std::str::from_utf8(buf) { + string.to_string() + } else { + let lossy_string = String::from_utf8_lossy(buf).into_owned(); + warn!("Error decoding utf8 (bytes: {buf:?}, lossy: \"{lossy_string})\""); + lossy_string + }) } impl Tag { |
