From 613fc34df73e60cd5ff4cae8006639e08cdecae3 Mon Sep 17 00:00:00 2001 From: Justin Aquadro Date: Fri, 24 Aug 2012 00:14:53 -0400 Subject: [PATCH] Fixed unicode handling bug in NBT Strings, which could result in an inconsistent NBT binary. --- SubstrateCS/Properties/AssemblyInfo.cs | 4 ++-- SubstrateCS/Source/Nbt/NbtTree.cs | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/SubstrateCS/Properties/AssemblyInfo.cs b/SubstrateCS/Properties/AssemblyInfo.cs index 2f1e2e3..138fd28 100644 --- a/SubstrateCS/Properties/AssemblyInfo.cs +++ b/SubstrateCS/Properties/AssemblyInfo.cs @@ -30,8 +30,8 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("1.3.3.0")] -[assembly: AssemblyFileVersion("1.3.3.0")] +[assembly: AssemblyVersion("1.3.4.0")] +[assembly: AssemblyFileVersion("1.3.4.0")] // This library is compatible with all CLS-compliant .NET programming languages. [assembly: CLSCompliant(true)] \ No newline at end of file diff --git a/SubstrateCS/Source/Nbt/NbtTree.cs b/SubstrateCS/Source/Nbt/NbtTree.cs index fce56c0..242d157 100644 --- a/SubstrateCS/Source/Nbt/NbtTree.cs +++ b/SubstrateCS/Source/Nbt/NbtTree.cs @@ -271,7 +271,7 @@ namespace Substrate.Nbt byte[] strBytes = new byte[len]; _stream.Read(strBytes, 0, len); - System.Text.Encoding str = Encoding.GetEncoding(28591); + System.Text.Encoding str = Encoding.UTF8; TagNodeString val = new TagNodeString(str.GetString(strBytes)); @@ -496,7 +496,10 @@ namespace Substrate.Nbt private void WriteString (TagNodeString val) { - byte[] lenBytes = BitConverter.GetBytes((short)val.Length); + System.Text.Encoding str = Encoding.UTF8; + byte[] gzBytes = str.GetBytes(val.Data); + + byte[] lenBytes = BitConverter.GetBytes((short)gzBytes.Length); if (BitConverter.IsLittleEndian) { Array.Reverse(lenBytes); @@ -504,9 +507,6 @@ namespace Substrate.Nbt _stream.Write(lenBytes, 0, 2); - System.Text.Encoding str = Encoding.GetEncoding(28591); - byte[] gzBytes = str.GetBytes(val.Data); - _stream.Write(gzBytes, 0, gzBytes.Length); }