Skip to content

Commit bde32bb

Browse files
authored
Merge pull request #33 from filipnavara/fix-string-collision
Fix string collision when two sections have the same name
2 parents 16aa919 + 634433d commit bde32bb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/LibObjectFile/Elf/Sections/ElfStringTable.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Diagnostics;
99
using System.IO;
1010
using System.Text;
11+
using System.Linq;
1112

1213
namespace LibObjectFile.Elf
1314
{
@@ -17,7 +18,7 @@ namespace LibObjectFile.Elf
1718
public class ElfStringTable : ElfSection
1819
{
1920
private readonly MemoryStream _table;
20-
private readonly List<string> _reservedStrings;
21+
private readonly HashSet<string> _reservedStrings;
2122
private readonly Dictionary<string, uint> _mapStringToIndex;
2223
private readonly Dictionary<uint, string> _mapIndexToString;
2324

@@ -36,7 +37,7 @@ public ElfStringTable(int capacityInBytes) : base(ElfSectionType.StringTable)
3637
_table = new MemoryStream(capacityInBytes);
3738
_mapStringToIndex = new Dictionary<string, uint>();
3839
_mapIndexToString = new Dictionary<uint, string>();
39-
_reservedStrings = new List<string>();
40+
_reservedStrings = new HashSet<string>();
4041
// Always create an empty string
4142
CreateIndex(string.Empty);
4243
}
@@ -78,7 +79,7 @@ protected override void Write(ElfWriter writer)
7879

7980
internal void ReserveString(string text)
8081
{
81-
if (text is object && !_mapStringToIndex.ContainsKey(text))
82+
if (text is object && !_mapStringToIndex.ContainsKey(text) && !_reservedStrings.Contains(text))
8283
{
8384
_reservedStrings.Add(text);
8485
}

0 commit comments

Comments
 (0)