Skip to content

[Rebase&FF] pecoff: add get_section functionality#1409

Open
Javagedes wants to merge 2 commits intoOpenDevicePartnership:mainfrom
Javagedes:personal/joeyvagedes/section-parse
Open

[Rebase&FF] pecoff: add get_section functionality#1409
Javagedes wants to merge 2 commits intoOpenDevicePartnership:mainfrom
Javagedes:personal/joeyvagedes/section-parse

Conversation

@Javagedes
Copy link
Contributor

@Javagedes Javagedes commented Mar 16, 2026

Description

This commit pulls the functionality for getting a sub-slice that represents a particular PE/COFF section from an unloaded image out of load_resource_section and makes it a re-usable function. It also removes an unnecessary allocation when comparing section names.

NOTE: The git diff does not do this change justice due to each line's "depth" being adjusted. There is no change in logic, except for the second commit, which removes the allocation.

  • Impacts functionality?
  • Impacts security?
  • Breaking change?
  • Includes tests?
  • Includes documentation?

How This Was Tested

CI continues to work. Boot on Q35.

Integration Instructions

N/A

@patina-automation
Copy link
Contributor

patina-automation bot commented Mar 16, 2026

✅ QEMU Validation Passed

All QEMU validation jobs completed successfully.

Note: Windows Q35 is only built (QEMU boot is disabled due to QEMU vfat issue).

Workflow run: https://github.com/OpenDevicePartnership/patina/actions/runs/23168269121

Boot Time to EFI Shell

Platform Elapsed
Linux Q35 43.9s
Linux SBSA 43.0s

This comment was automatically generated by the Patina QEMU PR Validation Post workflow.

@github-actions github-actions bot added impact:non-functional Does not have a functional impact impact:testing Affects testing labels Mar 16, 2026
@Javagedes Javagedes force-pushed the personal/joeyvagedes/section-parse branch from 23caab7 to 5e68499 Compare March 16, 2026 21:00
for _ in 0..directory.number_of_named_entries {
if directory_entry.name_is_string() {
if directory_entry.name_offset() >= size {
let name_start_offset = (directory_entry.name_offset() + 1) as usize;
Copy link
Collaborator

@makubacki makubacki Mar 16, 2026

Choose a reason for hiding this comment

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

I know this was pre-existing, but it seems a little strange for the name offset to start a byte (+ 1) in when a UTF-16 character is 2 bytes.

In the comment below: // L"HII" = [0x0, 0x48, 0x0, 0x49, 0x0, 0x49], the low-byte would typically have the ASCII character for UTF-16 little endian:

// L"HII" = [0x48, 0x0, 0x49, 0x0, 0x49, 0x0]

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you want, I can also take this up separately since it is unrelated to your PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joschock may have a better answer to this, but I assume that it has to do with the name_offset() being tied to the ID, and thus needing to do an offset by 1, similar to 0 or 1 based indexing. But I'm not familiar with this enough to answer confidently when it is working as-is.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have no memory of this place :) - I do not know what the +1 is. Maybe it is trying to skip the "length" field? But the length field is 2 bytes...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm going to resolve this. @makubacki would you like me to create an issue to have this investigated?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sure. I'm also interested to look in more detail if you want to assign me.

Javagedes and others added 2 commits March 16, 2026 14:57
Create a new function called `get_section` that returns the byte slice
representing the requested PE/COFF section from the specified image.

This logic is directly pulled from the `load_resource_section` and
moved into it's own function.
This commit removes an allocation done in `get_section` by comparing
the bytes of the two string, rather than allocating a new string based
off the bytes.
@Javagedes Javagedes force-pushed the personal/joeyvagedes/section-parse branch from 5e68499 to 7e819dc Compare March 16, 2026 21:57
@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

❌ Patch coverage is 80.51948% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
patina_dxe_core/src/pecoff.rs 80.52% 15 Missing ⚠️

📢 Thoughts on this report? Let us know!

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

Labels

impact:non-functional Does not have a functional impact impact:testing Affects testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants