Skip to content

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

Open
Sasinkas wants to merge 4 commits intomainfrom
dev/sraroseck/dwarf-memory-reader-exception-handeling
Open

Enhance DWARF memory reader with bounds checking and exception handli…#1167
Sasinkas wants to merge 4 commits 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

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Even if Position is 0, there might be a scenario where we want to read more bytes than length (Data.Length = 4 and bytesToRead = 8 -> that is the kind of scenario where first part is necessary

{
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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

exception changed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Well I put Position into exception so it would not make sense to change that

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