Fix too-long string values

This commit is contained in:
Matt Nadareski
2024-01-26 01:23:33 -05:00
parent 33905165f7
commit 88de4be27b

View File

@@ -1280,6 +1280,7 @@ namespace SabreTools.Serialization
{
var stringData = new StringData();
int dataStartOffset = offset;
stringData.Length = data.ReadUInt16(ref offset);
stringData.ValueLength = data.ReadUInt16(ref offset);
stringData.ResourceType = (VersionResourceType)data.ReadUInt16(ref offset);
@@ -1294,7 +1295,8 @@ namespace SabreTools.Serialization
if (stringData.ValueLength > 0)
{
byte[]? valueBytes = data.ReadBytes(ref offset, stringData.ValueLength * sizeof(ushort));
int bytesReadable = Math.Min(stringData.ValueLength * sizeof(ushort), stringData.Length - (offset - dataStartOffset));
byte[]? valueBytes = data.ReadBytes(ref offset, bytesReadable);
if (valueBytes != null)
stringData.Value = Encoding.Unicode.GetString(valueBytes);
}