Skip to content

fix(extract): normalize stat.st_mode to libc::mode_t for 32-bit Android - #1328

Merged
Pr0methean merged 1 commit into
zip-rs:masterfrom
ByGh00st:fix/android32-st-mode
Nov 19, 2026
Merged

Pr0methean merged 1 commit into
zip-rs:masterfrom
ByGh00st:fix/android32-st-mode

Conversation

@ByGh00st

@ByGh00st ByGh00st commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1327

Problem

On 32-bit Android targets (armv7-linux-androideabi, i686-linux-android, etc.), libc defines libc::mode_t (along with libc::S_IFMT, S_IFREG, S_IFDIR, and S_IFLNK) as u16, whereas libc::stat::st_mode is u32 (c_uint).

Because of this mismatch, building on 32-bit Android fails in src/read/extract.rs at:

  • open_dir_beneath, where desired inherits u32 from st.st_mode and is passed to libc::fchmod / libc::fchmodat expecting u16
  • All (*.st_mode & libc::S_IFMT) ==/!= libc::S_IF* checks (u32 vs u16)

Changes

  • Added a small const fn stat_mode(st: &libc::stat) -> libc::mode_t helper in src/read/extract.rs and updated all 9 st_mode sites to go through it.
  • Removed an unneeded return in the macOS/BSD branch of set_permissions_dirfd_entry that triggered clippy::needless_return when checking aarch64-apple-darwin.

Testing

  • Reproduced the original 26 compile errors on armv7-linux-androideabi before the fix.
  • Ran cargo clippy --lib --no-default-features -- -D warnings after the fix across 23 targets covering all mode_t / st_mode / endianness / pointer-width combinations (armv7-linux-androideabi, i686-linux-android, aarch64-linux-android, armv7-unknown-linux-gnueabihf, armv7-unknown-linux-musleabihf, x86_64-unknown-linux-gnu, s390x-unknown-linux-gnu, powerpc-unknown-linux-gnu, aarch64-apple-darwin, aarch64-apple-ios, x86_64-unknown-freebsd, x86_64-unknown-netbsd, x86_64-pc-solaris, x86_64-unknown-illumos, x86_64-unknown-redox, x86_64-pc-windows-msvc, i686-pc-windows-msvc, aarch64-pc-windows-msvc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, wasm32-unknown-emscripten, x86_64-unknown-fuchsia).
  • Verified cargo fmt --all -- --check and cargo test --lib --no-default-features on Windows host.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@amazon-q-developer

Copy link
Copy Markdown
Contributor

Warning

Amazon Q Developer for GitHub: end of support

On January 30, 2027, AWS will discontinue support for the Amazon Q Developer for GitHub App. New app installations will no longer be available starting November 18, 2026.

For capabilities similar to the Amazon Q Developer for GitHub App, explore Kiro and the Kiro GitHub App. For more information about the end of support, see Amazon Q Developer end-of-support announcement on the AWS DevOps Blog.

@amazon-q-developer amazon-q-developer Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The fix is correct and well-scoped. The new stat_mode helper function properly abstracts the st.st_mode as libc::mode_t narrowing cast needed on 32-bit Android targets (where libc::stat::st_mode is u32 but libc::mode_t is u16), and is a no-op on all other Unix platforms. All 9 call sites have been consistently updated, the #[allow(clippy::unnecessary_cast)] suppression is narrowly scoped with a clear comment, and the incidental return Ok(()) → Ok(()) cleanup is a valid clippy fix for the macOS/BSD branch.

No blocking issues found. The change is ready to merge.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

@ByGh00st
ByGh00st requested a review from Pr0methean November 19, 2026 04:52
On 32-bit Android targets (such as armv7-linux-androideabi and
i686-linux-android), libc defines libc::mode_t and the S_IF* constants
as u16, while libc::stat::st_mode is c_uint (u32). This caused type
mismatch errors when masking st_mode against S_IFMT / S_IF* and when
passing derived directory modes from open_dir_beneath to libc::fchmod
and libc::fchmodat.

Add a stat_mode helper in src/read/extract.rs to normalize st.st_mode
to libc::mode_t across all Unix call sites, and remove an unneeded
return in the macOS/BSD branch of set_permissions_dirfd_entry flagged
by clippy on macOS.

Fixes zip-rs#1327
@ByGh00st
ByGh00st force-pushed the fix/android32-st-mode branch from 83e37f9 to 1a4f331 Compare November 19, 2026 05:00
@Pr0methean
Pr0methean enabled auto-merge November 19, 2026 05:07
@Pr0methean
Pr0methean added this pull request to the merge queue Nov 19, 2026
Merged via the queue into zip-rs:master with commit f014455 Nov 19, 2026
103 of 128 checks passed
@ByGh00st
ByGh00st deleted the fix/android32-st-mode branch November 19, 2026 05:23
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.

zip-9.7.1: Build error on target arm-v7 with rust 1.96.1

2 participants