Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
[2023/07/15]
Browse files Browse the repository at this point in the history
* (fixed) StackOverflow exception when cloning the extended data associated to an application registry with circular references.
  • Loading branch information
haplokuon committed Jul 15, 2023
1 parent d53bd30 commit 9bb9df9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 84 deletions.
3 changes: 3 additions & 0 deletions doc/Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Change history

### [2023/07/15]
* (fixed) StackOverflow exception when cloning the extended data associated to an application registry with circular references.

### [3.0.0 - 2023/06/28]

[2023/06/28]
Expand Down
28 changes: 23 additions & 5 deletions netDxf/Tables/ApplicationRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,34 @@ public override List<DxfObjectReference> GetReferences()
/// <returns>A new ApplicationRegistry that is a copy of this instance.</returns>
public override TableObject Clone(string newName)
{
ApplicationRegistry copy = new ApplicationRegistry(newName);
// container to temporary store application registries that has already been cloned,
// this will handle possible circular references inside de extended data structure
Dictionary<string, ApplicationRegistry> cloned = new Dictionary<string, ApplicationRegistry>();
return CloneApplicationRegistry(this, ref cloned) ;
}

foreach (XData data in this.XData.Values)
private static ApplicationRegistry CloneApplicationRegistry(ApplicationRegistry appReg, ref Dictionary<string, ApplicationRegistry> cloned)
{
if (!cloned.TryGetValue(appReg.Name, out ApplicationRegistry copy))
{
copy.XData.Add((XData)data.Clone());
copy = new ApplicationRegistry(appReg.Name);
cloned.Add(copy.Name, copy);

foreach (XData data in appReg.XData.Values)
{
ApplicationRegistry xdataAppReg = CloneApplicationRegistry(data.ApplicationRegistry, ref cloned);
XData xdataCopy = new XData(xdataAppReg);
foreach (XDataRecord record in data.XDataRecord)
{
xdataCopy.XDataRecord.Add(new XDataRecord(record.Code, record.Value));
}
copy.XData.Add(xdataCopy);
}
}

return copy ;
return copy;
}

/// <summary>
/// Creates a new ApplicationRegistry that is a copy of the current instance.
/// </summary>
Expand Down
79 changes: 0 additions & 79 deletions netDxf/netDxf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20853,82 +20853,3 @@
</member>
</members>
</doc>
along with the parent (but is not moved, scaled, or stretched)
</summary>
</member>
<member name="F:netDxf.XDataCode.WorldDirectionZ">
<summary>
Also a 3D point that is rotated and mirrored along with the parent (but is not moved, scaled, or stretched)
</summary>
</member>
<member name="F:netDxf.XDataCode.Real">
<summary>
A real value.
</summary>
</member>
<member name="F:netDxf.XDataCode.Distance">
<summary>
A real value that is scaled along with the parent entity
</summary>
</member>
<member name="F:netDxf.XDataCode.ScaleFactor">
<summary>
Also a real value that is scaled along with the parent.
The difference between a distance and a scale factor is application-defined
</summary>
</member>
<member name="F:netDxf.XDataCode.Int16">
<summary>
A 16-bit integer (signed or unsigned).
</summary>
</member>
<member name="F:netDxf.XDataCode.Int32">
<summary>
A 32-bit signed integer.
</summary>
</member>
<member name="T:netDxf.XDataRecord">
<summary>
Represents an entry in the extended data of an entity.
</summary>
</member>
<member name="P:netDxf.XDataRecord.OpenControlString">
<summary>
An extended data control string can be either "{"or "}".
These braces enable applications to organize their data by subdividing the data into lists.
The left brace begins a list, and the right brace terminates the most recent list. Lists can be nested.
</summary>
</member>
<member name="P:netDxf.XDataRecord.CloseControlString">
<summary>
An extended data control string can be either "{" or "}".
These braces enable applications to organize their data by subdividing the data into lists.
The left brace begins a list, and the right brace terminates the most recent list. Lists can be nested.
</summary>
</member>
<member name="M:netDxf.XDataRecord.#ctor(netDxf.XDataCode,System.Object)">
<summary>
Initializes a new XDataRecord.
</summary>
<param name="code">XData code.</param>
<param name="value">XData value.</param>
</member>
<member name="P:netDxf.XDataRecord.Code">
<summary>
Gets the XData code.
</summary>
<remarks>The only valid values are the ones defined in the <see cref="T:netDxf.XDataCode">XDataCode</see> class.</remarks>
</member>
<member name="P:netDxf.XDataRecord.Value">
<summary>
Gets the XData value.
</summary>
</member>
<member name="M:netDxf.XDataRecord.ToString">
<summary>
Obtains a string that represents the XDataRecord.
</summary>
<returns>A string text.</returns>
</member>
</members>
</doc>

0 comments on commit 9bb9df9

Please sign in to comment.