From acff3573b2b3ce4986b4ae40b5bf1f7ff7f79a85 Mon Sep 17 00:00:00 2001 From: aone Date: Fri, 17 Jun 2022 10:42:49 +0200 Subject: [PATCH 1/2] Do not set entry size for directories (bad header) --- Sources/Tarscape/KBFileAttributes.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/Tarscape/KBFileAttributes.swift b/Sources/Tarscape/KBFileAttributes.swift index 082f733..3181ffb 100644 --- a/Sources/Tarscape/KBFileAttributes.swift +++ b/Sources/Tarscape/KBFileAttributes.swift @@ -45,7 +45,15 @@ public struct KBFileAttributes { self.fileType = isAlias ? .alias : FileType(mode: fileStat.st_mode) // File size. - self.fileSize = Int(fileStat.st_size) + // Some directories return a size using stat (return nil with FileManager), + // since we never write any data for directories adding here the size + // will produce a bad header that may cause issues when parsed + if self.fileType == .directory { + self.fileSize = 0 + } + else { + self.fileSize = Int(fileStat.st_size) + } // Modification date. let modTimeSpec = fileStat.st_mtimespec From 1892aa2e000dcd480d1156117678b9d2153f9457 Mon Sep 17 00:00:00 2001 From: aone Date: Fri, 17 Jun 2022 12:23:33 +0200 Subject: [PATCH 2/2] Do not set size in header for non files Leads to data corruption and parse issues (cherry picked from commit f3860ffd0bab83e6396f7d6fc86a28b7a30937a5) --- Sources/Tarscape/KBFileAttributes.swift | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/Tarscape/KBFileAttributes.swift b/Sources/Tarscape/KBFileAttributes.swift index 3181ffb..0948c2c 100644 --- a/Sources/Tarscape/KBFileAttributes.swift +++ b/Sources/Tarscape/KBFileAttributes.swift @@ -45,14 +45,14 @@ public struct KBFileAttributes { self.fileType = isAlias ? .alias : FileType(mode: fileStat.st_mode) // File size. - // Some directories return a size using stat (return nil with FileManager), - // since we never write any data for directories adding here the size - // will produce a bad header that may cause issues when parsed - if self.fileType == .directory { - self.fileSize = 0 + // Some directories and links return a size using stat (return nil with FileManager), + // since we never write any data for non "normalFile" adding here the size + // will produce a bad header that will cause issues when parsed and data corruption. + if self.fileType == .file { + self.fileSize = Int(fileStat.st_size) } else { - self.fileSize = Int(fileStat.st_size) + self.fileSize = 0 } // Modification date.