Compare commits

...

4 Commits
1.9.4 ... 1.9.5

Author SHA1 Message Date
Matt Nadareski
bf35b7c10b Bump version 2025-09-21 12:35:37 -04:00
Matt Nadareski
4026b8ca09 Handle differently-encoded XMLs as textfiles 2025-09-21 12:10:58 -04:00
Matt Nadareski
6d2e2d8c3b Handle some invalid parsing cases that were missed previously 2025-09-21 11:44:58 -04:00
Matt Nadareski
a2b08157cc Fix issue with split resource tables 2025-09-21 11:23:53 -04:00
7 changed files with 31 additions and 8 deletions

View File

@@ -10,7 +10,7 @@
<Nullable>enable</Nullable>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>1.9.4</Version>
<Version>1.9.5</Version>
</PropertyGroup>
<!-- Support All Frameworks -->

View File

@@ -10,7 +10,7 @@
<Nullable>enable</Nullable>
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>1.9.4</Version>
<Version>1.9.5</Version>
</PropertyGroup>
<!-- Support All Frameworks -->

View File

@@ -420,7 +420,14 @@ namespace SabreTools.Serialization.Deserializers
obj.RelocationRecords = new RelocationRecord[obj.RelocationRecordCount];
for (int i = 0; i < obj.RelocationRecords.Length; i++)
{
obj.RelocationRecords[i] = ParseRelocationRecord(data);
if (data.Position >= data.Length)
break;
var record = ParseRelocationRecord(data);
if (record == null)
break;
obj.RelocationRecords[i] = record;
}
return obj;
@@ -433,12 +440,20 @@ namespace SabreTools.Serialization.Deserializers
/// <returns>Filled RelocationRecord on success, null on error</returns>
public static RelocationRecord ParseRelocationRecord(Stream data)
{
// Handle partial relocation sections
if (data.Position > data.Length - 4)
return null;
var obj = new RelocationRecord();
obj.SourceType = (RelocationRecordSourceType)data.ReadByteValue();
obj.Flags = (RelocationRecordFlag)data.ReadByteValue();
obj.Offset = data.ReadUInt16LittleEndian();
// Handle incomplete entries
if (data.Position > data.Length - 4)
return obj;
switch (obj.Flags & RelocationRecordFlag.TARGET_MASK)
{
case RelocationRecordFlag.INTERNALREF:

View File

@@ -337,11 +337,11 @@ namespace SabreTools.Serialization.Deserializers
{
Name = new ResourceDirectoryString { UnicodeString = Encoding.Unicode.GetBytes("HIDDEN RESOURCE") },
IntegerID = uint.MaxValue,
DataEntryOffset = (uint)data.Position,
DataEntryOffset = (uint)tableOffset,
DataEntry = new ResourceDataEntry
{
Size = (uint)length,
Data = data.ReadBytes(length),
Data = tableData.ReadBytes(ref tableOffset, length),
Codepage = (uint)Encoding.Unicode.CodePage,
},
};
@@ -1601,7 +1601,7 @@ namespace SabreTools.Serialization.Deserializers
continue;
// If the offset is within the table data, read from there
if (nextOffset - tableStart + entry.DataEntry.Size <= tableLength)
if (nextOffset > tableStart && nextOffset - tableStart + entry.DataEntry.Size <= tableLength)
{
dataOffset = (int)(nextOffset - tableStart);
entry.DataEntry.Data = tableData.ReadBytes(ref dataOffset, (int)entry.DataEntry.Size);

View File

@@ -729,7 +729,7 @@ namespace SabreTools.Serialization
#region Creation data
dialogItemTemplate.CreationDataSize = entry.Data.ReadUInt16LittleEndian(ref offset);
if (dialogItemTemplate.CreationDataSize != 0)
if (dialogItemTemplate.CreationDataSize != 0 && dialogItemTemplate.CreationDataSize + offset < entry.Data.Length)
dialogItemTemplate.CreationData = entry.Data.ReadBytes(ref offset, dialogItemTemplate.CreationDataSize);
#endregion

View File

@@ -14,7 +14,7 @@
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Version>1.9.4</Version>
<Version>1.9.5</Version>
<!-- Package Properties -->
<Authors>Matt Nadareski</Authors>

View File

@@ -703,6 +703,14 @@ namespace SabreTools.Serialization.Wrappers
if (magic.StartsWith([0x3C, 0x3F, 0x78, 0x6D, 0x6C]))
return WrapperType.Textfile;
// "<?xml" in UTF-16 encoding
if (magic.StartsWith([0x3C, 0x00, 0x3F, 0x00, 0x78, 0x00, 0x6D, 0x00, 0x6C, 0x00]))
return WrapperType.Textfile;
// "<?xml" in UTF-16 encoding with byte order marks
if (magic.StartsWith([0xFF, 0xFE, 0x3C, 0x00, 0x3F, 0x00, 0x78, 0x00, 0x6D, 0x00, 0x6C, 0x00]))
return WrapperType.Textfile;
// "Description in Zip"
if (extension.Equals("diz", StringComparison.OrdinalIgnoreCase))
return WrapperType.Textfile;