Skip to content

LoadConfig cannot read cb size fix#472

Merged
m4b merged 2 commits intom4b:masterfrom
chf0x:patch-1
Jun 14, 2025
Merged

LoadConfig cannot read cb size fix#472
m4b merged 2 commits intom4b:masterfrom
chf0x:patch-1

Conversation

@chf0x
Copy link
Contributor

@chf0x chf0x commented Jun 13, 2025

Hi guys, I think we have a typo here. I attached a binary as an example where it fails
example.zip

Hi guys, I think we have a typo here (can provide a binary as an example where it fails)
@chf0x chf0x changed the title Update load_config.rs LoadConfig cannot read cb size fix Jun 13, 2025
@m4b
Copy link
Owner

m4b commented Jun 14, 2025

would you mind fixing the warnings in load_config.rs while you're there? i think i need to turn on warnings-as-failures in CI job

warning: variable does not need to be mutable
   --> src/pe/load_config.rs:217:13
    |
217 |         let mut read_arch_dependent_u64 = |offset: &mut usize| {
    |             ----^^^^^^^^^^^^^^^^^^^^^^^
    |             |
    |             help: remove this `mut`
    |
    = note: `#[warn(unused_mut)]` on by default

warning: unused variable: `size`
   --> src/pe/load_config.rs:349:13
    |
349 |         let size = bytes.pread::<u32>(0).map_err(|_| {
    |             ^^^^ help: if this is intentional, prefix it with an underscore: `_size`
    |
    = note: `#[warn(unused_variables)]` on by default

also @kkent030315 this last warning is a little odd, why is the size unused here? seems to be parsed and ignored, could be another latent bug?

@kkent030315
Copy link
Contributor

kkent030315 commented Jun 14, 2025

@m4b I might forgot to remove the unused size var, but that really doesn't matter in the case. The problem is in let bytes = bytes[offset..].pread::<&[u8]> where it returns zero sized slice even if the size and bytes are correct. I guess something is wrong in scroll implementation?

I found it very annoying these two cases are not identical... Please correct me if I am wrong!

let bytes = bytes[offset..].pread::<&[u8]>(dd.size as usize)

let bytes = bytes[offset..].pread_with::<&[u8]>(0, dd.size as usize)

@kkent030315
Copy link
Contributor

It is safe to delete mut from read_arch_dependent_u64, as well as let size. The size is being parsed within scroll traits so it remains semantically equivalent. @chf0x Thanks for the fix!

@chf0x
Copy link
Contributor Author

chf0x commented Jun 14, 2025

@kkent030315 I may be wrong, but in this case, we are reading from the offset dd.size, rather than reading dd.size bytes?

pread::<&[u8]>(dd.size as usize)

@kkent030315
Copy link
Contributor

kkent030315 commented Jun 14, 2025

@kkent030315 I may be wrong, but in this case, we are reading from the offset dd.size, rather than reading dd.size bytes?

pread::<&[u8]>(dd.size as usize)

You are very correct, it makes sense. thanks!

Was thought .pread::<&[u8]>(dd.size as usize) implies .pread_with::<&[u8]>(0, dd.size as usize) 😅

Copy link
Owner

@m4b m4b left a comment

Choose a reason for hiding this comment

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

Thank you!

@m4b m4b merged commit 075535c into m4b:master Jun 14, 2025
0 of 6 checks passed
@m4b
Copy link
Owner

m4b commented Jun 16, 2025

NB: non-breaking

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.

3 participants