aboutsummaryrefslogtreecommitdiff
path: root/azalea-nbt/src
diff options
context:
space:
mode:
authorUbuntu <github@matdoes.dev>2022-11-09 18:59:03 +0000
committerUbuntu <github@matdoes.dev>2022-11-09 18:59:03 +0000
commitad8b1b7b2405b39d0f86b7adb00df7662dcd1a19 (patch)
treecf61b61e2125e7d2ae91359c760f3a374bc24e58 /azalea-nbt/src
parent8de73c336fb15aa2108d09dba833c80339ef6671 (diff)
downloadazalea-drasl-ad8b1b7b2405b39d0f86b7adb00df7662dcd1a19.tar.xz
ignore bad utf8
Diffstat (limited to 'azalea-nbt/src')
-rwxr-xr-xazalea-nbt/src/decode.rs10
1 files changed, 9 insertions, 1 deletions
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 {