Skip to content

Commit

Permalink
Fix bug in which invalid data in the userentries would result in a crash
Browse files Browse the repository at this point in the history
  • Loading branch information
soopercool101 committed Oct 12, 2023
1 parent 51cd5be commit b4e08cc
Show file tree
Hide file tree
Showing 18 changed files with 20 additions and 18 deletions.
1 change: 0 additions & 1 deletion BrawlCrate/ExternalInterfacing/ColorSmash.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using BrawlCrate.NodeWrappers;
using BrawlCrate.UI;
using BrawlLib.Internal;
using BrawlLib.Internal.Windows.Forms;
using BrawlLib.SSBB.ResourceNodes;
using BrawlLib.Wii.Textures;
Expand Down
1 change: 0 additions & 1 deletion BrawlLib/Internal/ObjectExtension.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.ComponentModel;
using System.Linq;
using System.Windows.Markup;

namespace BrawlLib.Internal
{
Expand Down
2 changes: 1 addition & 1 deletion BrawlLib/SSBB/ResourceNodes/Animations/CHR0Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public override bool OnInitialize()
_originalPath = header->OrigPath;
}

(_userEntries = new UserDataCollection()).Read(header->UserData);
(_userEntries = new UserDataCollection()).Read(header->UserData, WorkingUncompressed);

return header->Group->_numEntries > 0;
}
Expand Down
2 changes: 1 addition & 1 deletion BrawlLib/SSBB/ResourceNodes/Animations/CLR0Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public override bool OnInitialize()
_originalPath = header->OrigPath;
}

(_userEntries = new UserDataCollection()).Read(header->UserData);
(_userEntries = new UserDataCollection()).Read(header->UserData, WorkingUncompressed);

return header->Group->_numEntries > 0;
}
Expand Down
2 changes: 1 addition & 1 deletion BrawlLib/SSBB/ResourceNodes/Animations/PAT0Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public override bool OnInitialize()
_originalPath = header->OrigPath;
}

(_userEntries = new UserDataCollection()).Read(header->UserData);
(_userEntries = new UserDataCollection()).Read(header->UserData, WorkingUncompressed);

//Get texture strings
for (int i = 0; i < texPtr; i++)
Expand Down
2 changes: 1 addition & 1 deletion BrawlLib/SSBB/ResourceNodes/Animations/SHP0Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public override bool OnInitialize()
_originalPath = header->OrigPath;
}

(_userEntries = new UserDataCollection()).Read(header->UserData);
(_userEntries = new UserDataCollection()).Read(header->UserData, WorkingUncompressed);

return header->Group->_numEntries > 0;
}
Expand Down
2 changes: 1 addition & 1 deletion BrawlLib/SSBB/ResourceNodes/Animations/SRT0Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public override bool OnInitialize()
_originalPath = header->OrigPath;
}

(_userEntries = new UserDataCollection()).Read(header->UserData);
(_userEntries = new UserDataCollection()).Read(header->UserData, WorkingUncompressed);

return header->Group->_numEntries > 0;
}
Expand Down
2 changes: 1 addition & 1 deletion BrawlLib/SSBB/ResourceNodes/Animations/VIS0Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public override bool OnInitialize()
_originalPath = header->OrigPath;
}

(_userEntries = new UserDataCollection()).Read(header->UserData);
(_userEntries = new UserDataCollection()).Read(header->UserData, WorkingUncompressed);

return header->Group->_numEntries > 0;
}
Expand Down
2 changes: 1 addition & 1 deletion BrawlLib/SSBB/ResourceNodes/Graphics/PLT0Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public override bool OnInitialize()

if (_version == 3)
{
(_userEntries = new UserDataCollection()).Read(Header3->UserData);
(_userEntries = new UserDataCollection()).Read(Header3->UserData, WorkingUncompressed);
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion BrawlLib/SSBB/ResourceNodes/Graphics/TEX0Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public override bool OnInitialize()

if (_version == 3)
{
(_userEntries = new UserDataCollection()).Read(Header3->UserData);
(_userEntries = new UserDataCollection()).Read(Header3->UserData, WorkingUncompressed);
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion BrawlLib/SSBB/ResourceNodes/MDL0/MDL0BoneNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ public override bool OnInitialize()

_extents = header->_extents;

(_userEntries = new UserDataCollection()).Read(header->UserDataAddress);
(_userEntries = new UserDataCollection()).Read(header->UserDataAddress, WorkingUncompressed);

//We don't want to process children because not all have been parsed yet.
//Child assignments will be handled by the parent group.
Expand Down
2 changes: 1 addition & 1 deletion BrawlLib/SSBB/ResourceNodes/MDL0/MDL0MaterialNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,7 @@ public override bool OnInitialize()
(_chan1 = Light->Channel1)._parent = this;
(_chan2 = Light->Channel2)._parent = this;

(_userEntries = new UserDataCollection()).Read(header->UserData(_initVersion));
(_userEntries = new UserDataCollection()).Read(header->UserData(_initVersion), WorkingUncompressed);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion BrawlLib/SSBB/ResourceNodes/MDL0/MDL0Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2477,7 +2477,7 @@ public override bool OnInitialize()
}
}

(_userEntries = new UserDataCollection()).Read(header->UserData);
(_userEntries = new UserDataCollection()).Read(header->UserData, WorkingUncompressed);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion BrawlLib/SSBB/ResourceNodes/SCN0/SCN0CameraNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public override bool OnInitialize()
_projType = (ProjectionType) (int) Data->_projectionType;

//Read user data
(_userEntries = new UserDataCollection()).Read(Data->UserData);
(_userEntries = new UserDataCollection()).Read(Data->UserData, WorkingUncompressed);

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion BrawlLib/SSBB/ResourceNodes/SCN0/SCN0LightNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ public override bool OnInitialize()
_spotFunc = Data->_spotFunc;

//Read user data
(_userEntries = new UserDataCollection()).Read(Data->UserData);
(_userEntries = new UserDataCollection()).Read(Data->UserData, WorkingUncompressed);

//Don't bother reading data if the entry is null
if (Name == "<null>")
Expand Down
2 changes: 1 addition & 1 deletion BrawlLib/SSBB/ResourceNodes/SCN0/SCN0Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public override bool OnInitialize()
_originalPath = header->OrigPath;
}

(_userEntries = new UserDataCollection()).Read(header->UserData);
(_userEntries = new UserDataCollection()).Read(header->UserData, WorkingUncompressed);

return header->Group->_numEntries > 0;
}
Expand Down
1 change: 0 additions & 1 deletion BrawlLib/SSBB/ResourceNodes/Stage Tables/TBCLNode.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BrawlLib.Internal;
using BrawlLib.SSBB.Types.ProjectPlus;
using BrawlLib.SSBB.Types.Stage_Tables;
using System;
using System.ComponentModel;
Expand Down
7 changes: 6 additions & 1 deletion BrawlLib/SSBB/UserData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BrawlLib.Internal;
using BrawlLib.SSBB.ResourceNodes;
using BrawlLib.SSBB.Types;
using System;
using System.Collections;
Expand Down Expand Up @@ -60,7 +61,7 @@ public override void SetValue(object component, object value)

public unsafe class UserDataCollection : CollectionBase, ICustomTypeDescriptor
{
public void Read(VoidPtr userDataAddr)
public void Read(VoidPtr userDataAddr, DataSource src)
{
if (userDataAddr == null)
{
Expand All @@ -73,7 +74,11 @@ public void Read(VoidPtr userDataAddr)
int count = group->_numEntries;
for (int i = 0; i < count; i++, pEntry++)
{
if (pEntry->_dataOffset > src.Length)
break;
UserDataEntry* entry = (UserDataEntry*) ((VoidPtr) group + pEntry->_dataOffset);
if (pEntry->_dataOffset + entry->_dataOffset > src.Length)
break;
UserDataClass d = new UserDataClass {_name = new string((sbyte*) group + pEntry->_stringOffset)};
VoidPtr addr = (VoidPtr) entry + entry->_dataOffset;
d._type = entry->Type;
Expand Down

0 comments on commit b4e08cc

Please sign in to comment.