Skip to content

Commit

Permalink
Fixed crash when reading WDB5s without index map
Browse files Browse the repository at this point in the history
  • Loading branch information
Marlamin committed Nov 23, 2024
1 parent 73d79e4 commit ea1d717
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DBCD.IO/Readers/WDB3Reader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void GetFields<T>(FieldCache<T>[] fields, T entry)
for (int i = 0; i < fields.Length; i++)
{
FieldCache<T> info = fields[i];
if (fields[i].IndexMapField)
if (info.IndexMapField)
{
if (Id != -1)
indexFieldOffSet++;
Expand Down
2 changes: 1 addition & 1 deletion DBCD.IO/Readers/WDB4Reader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void GetFields<T>(FieldCache<T>[] fields, T entry)
for (int i = 0; i < fields.Length; i++)
{
FieldCache<T> info = fields[i];
if (fields[i].IndexMapField)
if (info.IndexMapField)
{
if (Id != -1)
indexFieldOffSet++;
Expand Down
9 changes: 7 additions & 2 deletions DBCD.IO/Readers/WDB5Reader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ public void GetFields<T>(FieldCache<T>[] fields, T entry)
for (int i = 0; i < fields.Length; i++)
{
FieldCache<T> info = fields[i];
if (info.IndexMapField)

/*
* Note: While WDB5 was introduced in build 21479, idFieldIndex wasn't added to it until build 21737.
* This means that the check below here will likely fail for the ~6 builds between those.
*/
if (i == m_reader.IdFieldIndex)
{
if (Id != -1)
indexFieldOffSet++;
Expand Down Expand Up @@ -185,7 +190,7 @@ public WDB5Reader(Stream stream)
Locale = reader.ReadInt32();
int copyTableSize = reader.ReadInt32();
Flags = (DB2Flags)reader.ReadUInt16();
IdFieldIndex = reader.ReadUInt16();
IdFieldIndex = reader.ReadUInt16(); // Only in build 21737+, what happens in the ~6 builds between 21479 and 21737?

// field meta data
Meta = reader.ReadArray<FieldMetaData>(FieldsCount);
Expand Down

0 comments on commit ea1d717

Please sign in to comment.