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
12 changes: 6 additions & 6 deletions Sources/ContainerizationArchive/ArchiveReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,9 @@ extension ArchiveReader {
do {
switch type {
case .regular:
try rootFileDescriptor.mkdirSecure(relativePath, makeIntermediates: true) { fd in
try FileDescriptorOps.mkdir(rootFileDescriptor, relativePath, makeIntermediates: true) { fd in
// Remove existing entry if present (mimics containerd's "last entry wins" behavior)
try? fd.unlinkRecursiveSecure(filename: lastComponent)
try? FileDescriptorOps.unlinkRecursive(fd, filename: lastComponent)

// Open file for writing using openat with O_NOFOLLOW to prevent TOC-TOU attacks
let fileMode = entry.permissions & 0o777 // Mask to permission bits only
Expand All @@ -362,17 +362,17 @@ extension ArchiveReader {
setFileAttributes(fd: fileFd, entry: entry)
}
case .directory:
try rootFileDescriptor.mkdirSecure(memberPath, makeIntermediates: true) { fd in
try FileDescriptorOps.mkdir(rootFileDescriptor, memberPath, makeIntermediates: true) { fd in
setFileAttributes(fd: fd.rawValue, entry: entry)
}
case .symbolicLink:
guard let targetPath = (entry.symlinkTarget.map { FilePath($0) }) else {
return false
}
var symlinkCreated = false
try rootFileDescriptor.mkdirSecure(relativePath, makeIntermediates: true) { fd in
try FileDescriptorOps.mkdir(rootFileDescriptor, relativePath, makeIntermediates: true) { fd in
// Remove existing entry if present (mimics containerd's "last entry wins" behavior)
try? fd.unlinkRecursiveSecure(filename: lastComponent)
try? FileDescriptorOps.unlinkRecursive(fd, filename: lastComponent)

guard symlinkat(targetPath.string, fd.rawValue, lastComponent.string) == 0 else {
throw ArchiveError.failedToExtractArchive("failed to create symlink: \(targetPath) <- \(memberPath)")
Expand All @@ -385,7 +385,7 @@ extension ArchiveReader {
}

return true
} catch let error as SecurePathError {
} catch let error as FileDescriptorOps.Error {
// Just reject path validation errors, don't fail the extraction
switch error {
case .systemError:
Expand Down
218 changes: 0 additions & 218 deletions Sources/ContainerizationOS/FileDescriptor+SecurePath.swift

This file was deleted.

Loading
Loading