Skip to content

Commit fb99913

Browse files
Copilotbrianrob
andcommitted
Add clarifying comments about progressive read pattern and bounds checking
Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
1 parent d46532d commit fb99913

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/TraceEvent/TraceUtilities/PEFile.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,13 @@ internal PEHeader(PEBufferedSlice slice)
393393

394394
m_sectionsOffset = m_ntHeaderOffset + sizeof(IMAGE_NT_HEADERS) + ntHdr.FileHeader.SizeOfOptionalHeader;
395395

396-
// Note: We don't validate that the span contains all section headers here.
397-
// The PEFile constructor will check Header.PEHeaderSize and re-read with a larger buffer if needed.
398-
// ReadOnlySpan bounds checking will catch any actual out-of-bounds reads when accessing sections.
396+
// Note: We don't validate that the span contains all section headers at this point.
397+
// This is intentional to support the progressive read pattern in PEFile:
398+
// 1. PEFile creates PEHeader with initial 1024-byte buffer
399+
// 2. PEFile checks Header.PEHeaderSize (which needs m_sectionsOffset + section count)
400+
// 3. If PEHeaderSize > buffer length, PEFile re-reads with correct size
401+
// 4. ReadOnlySpan bounds checking catches any out-of-bounds access when sections are actually read
402+
// This pattern allows PE files with large headers (>1024 bytes) to work correctly.
399403

400404
return;
401405
ThrowBadHeader:

0 commit comments

Comments
 (0)