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

Trim 0b/0o/0x prefixes when parsing numbers. #35

Merged
merged 2 commits into from
Jul 21, 2024

Conversation

cuiwc
Copy link
Contributor

@cuiwc cuiwc commented Jul 3, 2024

In some rare cases, the file mode field in the headers of an ar package could have "0o" as prefix since the radix is 8. This change tries to trim radix prefixes when parsing numbers, as the current Rust from_str_radix API doesn't parse radix prefixes yet (refer to rust-lang/rfcs#1098).

@mdsteele
Copy link
Owner

mdsteele commented Jul 5, 2024

Could you add new unit test(s) for this?

@mdsteele
Copy link
Owner

mdsteele commented Jul 5, 2024

Also, out of curiosity, do you have any examples of archive files/tools in the wild that use such a prefix?

@cuiwc
Copy link
Contributor Author

cuiwc commented Jul 8, 2024

Thanks, @mdsteele.

Added a test with entry having "0o" prefix in the file mode field. Passed cargo fmt and cargo test verifications.

I ran across this issue with a VMware vSphere Installation Bundle (Vib) file, which is basically an ar archive but with file mode set to 0o0:

$ file VMW_bootbank_content.vib
VMW_bootbank_content.vib: current ar archive

$ head -c 100 VMW_bootbank_content.vib
!<arch>
descriptor.xml  0           0     0     0o0     3747      `
<vib version="5.0"><type>bootban%

The number parser returns "Invalid file mode field in entry header" error for this field. The ar program can extract this archive successfully.

@mdsteele mdsteele merged commit 755fc74 into mdsteele:master Jul 21, 2024
4 checks passed
@mdsteele
Copy link
Owner

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.

2 participants