Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write: fix reserving empty section error #514

Merged
merged 1 commit into from
Feb 17, 2023
Merged

Conversation

lzw3232
Copy link
Contributor

@lzw3232 lzw3232 commented Feb 16, 2023

if we copy a elf with a empty section and the sh_addralign(align_start) is not 0, it will return a unaligned offset.

@lzw3232 lzw3232 force-pushed the master branch 2 times, most recently from d0e19ed to 3e5fccf Compare February 16, 2023 11:35
@philipc
Copy link
Contributor

philipc commented Feb 16, 2023

Thanks for the PR. However, it does not look correct. Can you give an in depth explanation so I can better understand the problem? Are you running the elfcopy example? How does the unaligned offset cause an error?

@lzw3232
Copy link
Contributor Author

lzw3232 commented Feb 16, 2023

Thanks for the PR. However, it does not look correct. Can you give an in depth explanation so I can better understand the problem? Are you running the elfcopy example? How does the unaligned offset cause an error?

for example, the reserved_len is 64. then the first section's len is 42, align_start is 16. the offset is 64. But next section's len is 0, align_start is 16. the offset should be 112, but the offset is 106.
you can run elfcopy with this elf https://github.com/lzw3232/test.

@philipc
Copy link
Contributor

philipc commented Feb 16, 2023

Ok, and does that offset of 106 causes problems? It does sound like something that needs fixing, but I want to understand the problem first.

@lzw3232
Copy link
Contributor Author

lzw3232 commented Feb 16, 2023

Ok, and does that offset of 106 causes problems? It does sound like something that needs fixing, but I want to understand the problem first.

yes,the 106/16 is not a integer. so it is a unaligned offset.

@philipc
Copy link
Contributor

philipc commented Feb 17, 2023

Yes I understand what an unaligned offset is. What were you doing that caused you to notice that this is a problem?

I see that running elfcopy on it gives an error:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `106`,
 right: `112`', crates/examples/src/bin/elfcopy.rs:506:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Is that all that you were trying to do, or are you trying to use this code in something else where the unaligned offset causes a problem?

@lzw3232
Copy link
Contributor Author

lzw3232 commented Feb 17, 2023

Yes I understand what an unaligned offset is. What were you doing that caused you to notice that this is a problem?

I see that running elfcopy on it gives an error:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `106`,
 right: `112`', crates/examples/src/bin/elfcopy.rs:506:21
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Is that all that you were trying to do, or are you trying to use this code in something else where the unaligned offset causes a problem?

I just want to copy a elf with a empty section. This function said that "Returns the aligned offset of the start of the range". But if len is 0, it doesn't call "util::align" just return "self.len". Then I think this is a problem.

src/write/elf/writer.rs Show resolved Hide resolved
if we copy a elf with a empty section and the sh_addralign is not 0,
it will return a unaligned offset.

Signed-off-by: lzwycc <lzw32321226@163.com>
Copy link
Contributor

@philipc philipc left a comment

Choose a reason for hiding this comment

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

Thanks!

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.

None yet

2 participants