Skip to content

Commit 7aec71b

Browse files
committed
Fix long strings reading/writing
1 parent 6f2f8b1 commit 7aec71b

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
SubstrateCS/Release/
66
*.sdf
77
*.user
8+
**/UserPrefs.xml

SubstrateCS/Source/Nbt/NbtTree.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,7 @@ private TagNode ReadString ()
269269
Array.Reverse(lenBytes);
270270
}
271271

272-
short len = BitConverter.ToInt16(lenBytes, 0);
273-
if (len < 0) {
274-
throw new NBTException(NBTException.MSG_READ_NEG);
275-
}
272+
ushort len = BitConverter.ToUInt16(lenBytes, 0);
276273

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

577-
byte[] lenBytes = BitConverter.GetBytes((short)gzBytes.Length);
574+
byte[] lenBytes = BitConverter.GetBytes((ushort)gzBytes.Length);
578575

579576
if (BitConverter.IsLittleEndian) {
580577
Array.Reverse(lenBytes);

0 commit comments

Comments
 (0)