Skip to content

Commit

Permalink
Fix long strings reading/writing
Browse files Browse the repository at this point in the history
  • Loading branch information
Foghrye4 committed Jul 28, 2018
1 parent 6f2f8b1 commit 7aec71b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
SubstrateCS/Release/
*.sdf
*.user
**/UserPrefs.xml
7 changes: 2 additions & 5 deletions SubstrateCS/Source/Nbt/NbtTree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,7 @@ private TagNode ReadString ()
Array.Reverse(lenBytes);
}

short len = BitConverter.ToInt16(lenBytes, 0);
if (len < 0) {
throw new NBTException(NBTException.MSG_READ_NEG);
}
ushort len = BitConverter.ToUInt16(lenBytes, 0);

byte[] strBytes = new byte[len];
_stream.Read(strBytes, 0, len);
Expand Down Expand Up @@ -574,7 +571,7 @@ private void WriteString (TagNodeString val)
System.Text.Encoding str = Encoding.UTF8;
byte[] gzBytes = str.GetBytes(val.Data);

byte[] lenBytes = BitConverter.GetBytes((short)gzBytes.Length);
byte[] lenBytes = BitConverter.GetBytes((ushort)gzBytes.Length);

if (BitConverter.IsLittleEndian) {
Array.Reverse(lenBytes);
Expand Down

0 comments on commit 7aec71b

Please sign in to comment.