Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion crates/archive-trait/src/builder/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ impl FilePayload<'static> {
impl<B: ArchiveBuilder> Builder<B> {
/// Recursively adds a filesystem directory beneath its UTF-8 basename.
///
/// On Unix, the owner execute bit determines whether a regular file is
/// marked executable in the archive.
///
/// Entries are visited in deterministic sorted order and files are streamed
/// with bounded memory and default file options. Source symbolic links are
/// rejected by default;
Expand Down Expand Up @@ -350,7 +353,7 @@ impl SourceError {
fn is_executable(metadata: &std::fs::Metadata) -> bool {
use std::os::unix::fs::PermissionsExt;

metadata.permissions().mode() & 0o111 != 0
metadata.permissions().mode() & 0o100 != 0
}

#[cfg(not(unix))]
Expand Down
3 changes: 2 additions & 1 deletion crates/archive-trait/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ pub enum Member<P> {
/// `payload` must yield exactly this many bytes before completing
/// successfully. Format-level framing and compression are excluded.
size: u64,
/// Whether the archived mode carries executable intent.
/// Whether the archive marks the file executable. For Unix modes,
/// this reflects the owner execute bit (`0o100`).
executable: bool,
/// The streaming member payload.
payload: P,
Expand Down
8 changes: 5 additions & 3 deletions crates/archive-trait/tests/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,10 @@ async fn recursive_build_sorts_entries_batches_small_files_and_streams_large_fil
{
use std::os::unix::fs::PermissionsExt as _;

std::fs::set_permissions(source.join("a"), std::fs::Permissions::from_mode(0o755))
.expect("executable permissions should be set");
for (name, mode) in [("a", 0o744), ("z", 0o655)] {
std::fs::set_permissions(source.join(name), std::fs::Permissions::from_mode(mode))
.expect("source permissions should be set");
}
}

let format = MockFormat::new();
Expand Down Expand Up @@ -541,7 +543,7 @@ async fn recursive_build_sorts_entries_batches_small_files_and_streams_large_fil
)));
assert!(entries.iter().any(|entry| matches!(
entry,
RecordedEntry::File { path, data, chunks, .. }
RecordedEntry::File { path, data, chunks, executable: false, .. }
if path == "tree/z" && data == b"last" && *chunks == 1
)));
for (name, byte) in [("a", b'a'), ("b", b'b'), ("c", b'c')] {
Expand Down
2 changes: 1 addition & 1 deletion crates/tar-codec/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ fn decode_member<'a, R>(
let position = frame.header.position;
let kind = frame.header.kind;
let size = frame.header.effective_size;
let executable = frame.header.mode.unwrap_or_default() & 0o111 != 0;
let executable = frame.header.mode.unwrap_or_default() & 0o100 != 0;
let path = std::str::from_utf8(frame.effective_path()?)
.map(str::to_owned)
.map_err(|_| DecodeError::InvalidUtf8 {
Expand Down
11 changes: 10 additions & 1 deletion crates/tar-codec/tests/members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ async fn ignoring_trailing_data_leaves_the_reader_at_the_marker() -> TestResult
async fn projects_every_member_kind_and_streams_payloads() -> TestResult {
let mut archive = ArchiveBuilder::new();
archive
.ustar("file", b'0', b"contents", "", 0o755)
.ustar("file", b'0', b"contents", "", 0o744)
.ustar("group", b'0', b"", "", 0o654)
.ustar("other", b'0', b"", "", 0o645)
.ustar("contiguous", b'7', b"contiguous", "", 0o644)
.ustar("directory", b'5', b"", "", 0o755)
.ustar("symbolic", b'2', b"", "file", 0o777)
Expand All @@ -151,6 +153,13 @@ async fn projects_every_member_kind_and_streams_payloads() -> TestResult {
assert!(executable);
assert_eq!(read_payload(payload).await?, b"contents");

for path in ["group", "other"] {
assert!(matches!(
members.next().await?,
Some(Member::File { metadata, executable: false, .. }) if metadata.path == path
));
}

let Some(Member::File {
metadata, payload, ..
}) = members.next().await?
Expand Down
6 changes: 2 additions & 4 deletions crates/zip-codec/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::io::{self, SeekFrom};
use archive_trait::{Archive, Member, MemberMetadata, MemberPayload, SpecialKind};
use thiserror::Error;
use tokio::io::{AsyncRead, AsyncSeek, AsyncSeekExt};
use zip_framing::{Entry, EntryKind, Index, IndexPolicy, IndexedEntry, constants::attributes};
use zip_framing::{Entry, EntryKind, Index, IndexPolicy, IndexedEntry};

pub use zip_framing::{
CommentPolicy, CommentRule, ExtraFieldPolicy, ExtraHeaderId, ExtraHeaderIdSet,
Expand Down Expand Up @@ -380,9 +380,7 @@ impl<'a> TryFrom<&'a Entry<'_>> for Kind<'a> {
fn try_from(entry: &'a Entry<'_>) -> Result<Self, Self::Error> {
let directory = entry.directory();
match entry.kind() {
EntryKind::File => Ok(Self::File(
entry.unix_mode() & attributes::UNIX_EXECUTABLE != 0,
)),
EntryKind::File => Ok(Self::File(entry.unix_mode() & 0o100 != 0)),
EntryKind::Directory => Ok(Self::Directory),
EntryKind::SymbolicLink { unix_target } => {
if directory.size() > u64::from(u16::MAX) {
Expand Down
13 changes: 13 additions & 0 deletions crates/zip-codec/tests/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,19 @@ async fn opts_in_to_literal_backslashes_in_member_names() -> TestResult {
Ok(())
}

#[tokio::test]
async fn only_owner_execute_marks_a_file_executable() -> TestResult {
for (mode, expected) in [(0o100654, false), (0o100645, false), (0o100744, true)] {
let bytes = member_with_attributes(&[], HostSystem::Unix, mode << 16)?;
let mut archive = ZipArchive::open(Cursor::new(bytes)).await?;
let Some(Member::File { executable, .. }) = archive.member(0).await? else {
return Err(io::Error::other("expected regular file member").into());
};
assert_eq!(executable, expected, "mode {mode:o}");
}
Ok(())
}

#[tokio::test]
async fn enforces_kind_projection_after_metadata_resolution() -> TestResult {
for (attributes, expected_kind, expected_error) in [
Expand Down
Loading