Skip to content

Commit 733c62e

Browse files
committed
By default do not run security checks when packing
1 parent 9c85a5f commit 733c62e

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

Codec/Archive/Tar.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ module Codec.Archive.Tar (
106106
-- and permissions or to archive special files like named pipes and Unix
107107
-- device files.
108108
pack,
109-
packWith,
109+
packAndCheck,
110110
unpack,
111111
unpackWith,
112112

Codec/Archive/Tar/Pack.hs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
-----------------------------------------------------------------------------
1818
module Codec.Archive.Tar.Pack (
1919
pack,
20-
packWith,
20+
packAndCheck,
2121
packFileEntry,
2222
packDirectoryEntry,
2323
packSymlinkEntry,
@@ -31,6 +31,7 @@ import Codec.Archive.Tar.Types
3131
import Control.Monad (join, when, forM, (>=>))
3232
import qualified Data.ByteString as B
3333
import qualified Data.ByteString.Lazy as BL
34+
import Data.Foldable
3435
import System.FilePath
3536
( (</>) )
3637
import qualified System.FilePath as FilePath.Native
@@ -68,21 +69,22 @@ pack
6869
:: FilePath -- ^ Base directory
6970
-> [FilePath] -- ^ Files and directories to pack, relative to the base dir
7071
-> IO [Entry]
71-
pack = packWith checkSecurity
72+
pack = packAndCheck (const $ pure ())
7273

73-
-- | Like 'pack', but does not perform any sanity/security checks on the input.
74-
-- You can do so yourself, e.g.: @packWith@ 'checkSecurity' @dir@ @files@.
74+
-- | Like 'pack', but allows to specify any sanity/security checks on the input
75+
-- filenames.
7576
--
7677
-- @since 0.6.0.0
77-
packWith
78+
packAndCheck
7879
:: CheckSecurityCallback
7980
-> FilePath -- ^ Base directory
8081
-> [FilePath] -- ^ Files and directories to pack, relative to the base dir
8182
-> IO [Entry]
82-
packWith secCB baseDir =
83-
preparePaths baseDir >=>
84-
packPaths secCB baseDir >=>
85-
(pure . concatMap encodeLongNames)
83+
packAndCheck secCB baseDir relpaths = do
84+
paths <- preparePaths baseDir relpaths
85+
entries <- packPaths baseDir paths
86+
traverse_ secCB entries
87+
pure $ concatMap encodeLongNames entries
8688

8789
preparePaths :: FilePath -> [FilePath] -> IO [FilePath]
8890
preparePaths baseDir = fmap concat . interleave . map go
@@ -101,21 +103,18 @@ preparePaths baseDir = fmap concat . interleave . map go
101103

102104
-- | Pack paths while accounting for overlong filepaths.
103105
packPaths
104-
:: CheckSecurityCallback
105-
-> FilePath
106+
:: FilePath
106107
-> [FilePath]
107108
-> IO [GenEntry FilePath FilePath]
108-
packPaths secCB baseDir paths = interleave $ flip map paths $ \relpath -> do
109+
packPaths baseDir paths = interleave $ flip map paths $ \relpath -> do
109110
let isDir = FilePath.Native.hasTrailingPathSeparator abspath
110111
abspath = baseDir </> relpath
111112
isSymlink <- pathIsSymbolicLink abspath
112113
let mkEntry
113114
| isSymlink = packSymlinkEntry
114115
| isDir = packDirectoryEntry
115116
| otherwise = packFileEntry
116-
e <- mkEntry abspath relpath
117-
secCB e
118-
pure e
117+
mkEntry abspath relpath
119118

120119
interleave :: [IO a] -> IO [a]
121120
interleave = unsafeInterleaveIO . go

0 commit comments

Comments
 (0)