Skip to content

Commit

Permalink
First obtain correct number of sections, then read string table.
Browse files Browse the repository at this point in the history
Fixes #89.
  • Loading branch information
konrad-kruczynski committed Nov 14, 2022
1 parent 4e1a6dd commit 9ca7cf3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.15.2] - 2022-11-14
### Fixed
- ELF: case when section number is larger than `SHN_LORESERVE` and string table is present is now handled properly.

## [2.15.1] - 2022-11-12
### Fixed
- ELF: case when section number is larger than `SHN_LORESERVE` is now handled properly.
Expand Down
18 changes: 9 additions & 9 deletions ELFSharp/ELF/ELF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,6 @@ private void ReadSections()
sectionIndicesByName = new Dictionary<string, int>();
}

// If the number of sections is greater than or equal to SHN_LORESERVE (0xff00), this member has the
// value zero and the actual number of section header table entries is contained in the sh_size field
// of the section header at index 0. (Otherwise, the sh_size member of the initial entry contains 0.)
if (sectionHeaderEntryCount == 0)
{
var firstSectionHeader = ReadSectionHeader(0, true);
sectionHeaderEntryCount = checked((uint)firstSectionHeader.Size);
}

for (var i = 0; i < sectionHeaderEntryCount; i++)
{
var header = ReadSectionHeader(i);
Expand Down Expand Up @@ -370,6 +361,15 @@ private void ReadFields()
sectionHeaderEntrySize = reader.ReadUInt16();
sectionHeaderEntryCount = reader.ReadUInt16();
stringTableIndex = reader.ReadUInt16();

// If the number of sections is greater than or equal to SHN_LORESERVE (0xff00), this member has the
// value zero and the actual number of section header table entries is contained in the sh_size field
// of the section header at index 0. (Otherwise, the sh_size member of the initial entry contains 0.)
if (sectionHeaderEntryCount == 0)
{
var firstSectionHeader = ReadSectionHeader(0, true);
sectionHeaderEntryCount = checked((uint)firstSectionHeader.Size);
}
}

private GetSectionResult TryGetSectionInner(string name, out Section<T> section)
Expand Down
4 changes: 2 additions & 2 deletions ELFSharp/ELFSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
<TargetFramework>netstandard2.0</TargetFramework>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>sgKey.snk</AssemblyOriginatorKeyFile>
<Version>2.15.1.0</Version>
<Version>2.15.2.0</Version>
<AssemblyVersion>2.0</AssemblyVersion>
<Authors>Konrad Kruczyński, Piotr Zierhoffer, Łukasz Kucharski, Bastian Eicher, Cameron, Everett Maus, Fox, Reuben Olinsky, Connor Christie, Rollrat, Ulysses Wu, Cédric Luthi, Yong Yan, Filip Navara, Dedmen Miller, Murat Ocaktürk</Authors>
<Owners>Konrad Kruczyński</Owners>
<PackageProjectUrl>http://elfsharp.it/</PackageProjectUrl>
<PackageReleaseNotes>Fixed bug when wrong ELF section numbers count is read. Detailed changelog available at: https://github.com/konrad-kruczynski/elfsharp/blob/master/CHANGELOG.md</PackageReleaseNotes>
<PackageReleaseNotes>Fixed bug with reading string table with large numbers of sections. Detailed changelog available at: https://github.com/konrad-kruczynski/elfsharp/blob/master/CHANGELOG.md</PackageReleaseNotes>
<Summary>C# library for reading binary ELF, UImage, Mach-O files</Summary>
<PackageTags>ELF UImage Mach-O</PackageTags>
<Title>ELFSharp</Title>
Expand Down

0 comments on commit 9ca7cf3

Please sign in to comment.