Skip to content

Enhance DWARF memory reader with bounds checking and exception handli…#1167

Open
Sasinkas wants to merge 1 commit intomainfrom
dev/sraroseck/dwarf-memory-reader-exception-handeling
Open

Enhance DWARF memory reader with bounds checking and exception handli…#1167
Sasinkas wants to merge 1 commit intomainfrom
dev/sraroseck/dwarf-memory-reader-exception-handeling

Conversation

@Sasinkas
Copy link
Copy Markdown
Contributor

@Sasinkas Sasinkas commented Apr 1, 2026

…ng for read operations

@Sasinkas Sasinkas requested a review from a team as a code owner April 1, 2026 09:10
reader.Peek().Should().Be(0x42);
reader.Position.Should().Be(0);
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this file actually compile? :)


private void EnsureAvailable(uint bytesToRead)
{
if (bytesToRead > (uint)Data.Length || Position > (uint)Data.Length - bytesToRead)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First part in front of || seems redundant (it's equivalent of second part, with Position = 0)

{
if (bytesToRead > (uint)Data.Length || Position > (uint)Data.Length - bytesToRead)
{
throw new InvalidOperationException("Attempted to read past end of DWARF data buffer.");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking if we should not set position to the end of the data as well. To make sure no loop tries to re-read that broken sequence (if they would not handle the exception correctly)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, would it be worth having our custom exception for this scenario?

Comment on lines +224 to +227
if (Position >= Data.Length)
{
throw new InvalidOperationException("Attempted to read past end of DWARF data buffer.");
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be redundant with the check in first iteration of while

Comment on lines +252 to +256
if (Position >= Data.Length)
{
Position = startPosition;
throw new InvalidOperationException("Attempted to read past end of DWARF data buffer.");
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also redundant - it does the same check as last iteration of the while above

@@ -224,17 +265,45 @@ public ulong ULEB128()
/// </summary>
public uint SLEB128()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same questions as for ULEB128 above

@@ -224,17 +265,45 @@ public ulong ULEB128()
/// </summary>
public uint SLEB128()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same questions as for ULEB128 above

@@ -83,6 +92,7 @@ public byte Peek()
/// <typeparam name="T">Type of the structure to be read</typeparam>
public T ReadStructure<T>()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is missing test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants