Skip to content

uki: Get raw section from UKI#198

Merged
Johan-Liebert1 merged 1 commit intocomposefs:mainfrom
Johan-Liebert1:uki-raw-section
Dec 16, 2025
Merged

uki: Get raw section from UKI#198
Johan-Liebert1 merged 1 commit intocomposefs:mainfrom
Johan-Liebert1:uki-raw-section

Conversation

@Johan-Liebert1
Copy link
Collaborator

Add a function to get the raw section out of a UKI without converting it to a string.

Useful in bootc for checking kernel skew while performing soft-reboot

Copy link
Collaborator

@allisonkarlitskaya allisonkarlitskaya left a comment

Choose a reason for hiding this comment

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

This looks more or less correct now, minus one question. Can you squash the commits since the second one is just deleting most of the code from the first one?

let (pe_header, rest) = PeHeader::ref_from_prefix(rest).ok()?;
if pe_header.pe_magic != PE_MAGIC {
return None;
return Some(Err(UkiError::PortableExecutableError));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was this change required?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not really, but thought it conveys the intent better? If there is a header mismatch then we can consider it as an error

@Johan-Liebert1
Copy link
Collaborator Author

Squashed the commits into one

Comment on lines +93 to +95
/// * `None` - If the PE format is invalid or cannot be parsed
/// * `Some(Ok(&str))` - If the section is found and contains valid UTF-8
/// * `Some(Err(UkiError))` - If the section is missing or contains invalid UTF-8
Copy link
Collaborator

Choose a reason for hiding this comment

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

These docs are wrong now, sorry :(

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, my bad

Comment on lines +117 to +119
/// * `None` - If the PE format is invalid or cannot be parsed
/// * `Some(Ok(&[u8]))` - If the section is found, containing the raw section data
/// * `Some(Err(UkiError::MissingSection))` - If the section is not found in the PE file
Copy link
Collaborator

Choose a reason for hiding this comment

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

And since you changed the error return below from None to an explicit PortableExecutableError you should add it here (or just change it back)...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah yeah, I guess return type None does make things consistent. I'll revert my change

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Reverted the return type, fixed docs and pushed

Add a function to get the raw section out of a UKI without converting it
to a string.

Useful in bootc for checking kernel skew while performing soft-reboot

Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>

uki: Refactor `get_text_section` to return `Result`

In `get_section` return an error on PE Header mismatch

Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
Copy link
Collaborator

@allisonkarlitskaya allisonkarlitskaya left a comment

Choose a reason for hiding this comment

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

Thanks for the 27 go-arounds :)

@Johan-Liebert1
Copy link
Collaborator Author

Thanks for the 27 go-arounds :)

:)

@Johan-Liebert1 Johan-Liebert1 merged commit 1498349 into composefs:main Dec 16, 2025
14 of 15 checks passed
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