Fix Unicode string reading

This commit is contained in:
Matt Nadareski
2024-04-29 12:43:44 -04:00
parent ee7ce59627
commit 3de5b2378d
3 changed files with 6 additions and 6 deletions

View File

@@ -405,10 +405,10 @@ namespace SabreTools.IO.Extensions
return null;
ushort size = reader.ReadUInt16();
if (reader.BaseStream.Position + size >= reader.BaseStream.Length)
if (reader.BaseStream.Position + (size * 2) >= reader.BaseStream.Length)
return null;
byte[] buffer = reader.ReadBytes(size);
byte[] buffer = reader.ReadBytes(size * 2);
return Encoding.Unicode.GetString(buffer);
}

View File

@@ -533,10 +533,10 @@ namespace SabreTools.IO.Extensions
return null;
ushort size = content.ReadUInt16(ref offset);
if (offset + size >= content.Length)
if (offset + (size * 2) >= content.Length)
return null;
byte[] buffer = content.ReadBytes(ref offset, size);
byte[] buffer = content.ReadBytes(ref offset, size * 2);
return Encoding.Unicode.GetString(buffer);
}

View File

@@ -517,10 +517,10 @@ namespace SabreTools.IO.Extensions
return null;
ushort size = stream.ReadUInt16();
if (stream.Position + size >= stream.Length)
if (stream.Position + (size * 2) >= stream.Length)
return null;
byte[] buffer = stream.ReadBytes(size);
byte[] buffer = stream.ReadBytes(size * 2);
return Encoding.Unicode.GetString(buffer);
}