Interpret version field according to spec
This commit is contained in:
parent
5776d7bfaa
commit
f1e610d48f
@ -1,5 +1,5 @@
|
||||
module Codec.Archive.Zip.Conduit.Internal
|
||||
( zipVersion
|
||||
( osVersion, zipVersion
|
||||
, zipError
|
||||
, idConduit
|
||||
, sizeCRC
|
||||
@ -15,14 +15,18 @@ import qualified Data.ByteString as BS
|
||||
import qualified Data.Conduit as C
|
||||
import qualified Data.Conduit.Internal as CI
|
||||
import Data.Digest.CRC32 (crc32Update)
|
||||
import Data.Word (Word16, Word32, Word64)
|
||||
import Data.Word (Word8, Word16, Word32, Word64)
|
||||
|
||||
import Codec.Archive.Zip.Conduit.Types
|
||||
|
||||
-- |The version of this zip program, really just rough indicator of compatibility
|
||||
zipVersion :: Word16
|
||||
-- | The version of this zip program, really just rough indicator of compatibility
|
||||
zipVersion :: Word8
|
||||
zipVersion = 48
|
||||
|
||||
-- | The OS this implementation tries to be compatible to
|
||||
osVersion :: Word8
|
||||
osVersion = 0 -- DOS
|
||||
|
||||
zipError :: MonadThrow m => String -> m a
|
||||
zipError = throwM . ZipError
|
||||
|
||||
|
||||
@ -151,7 +151,8 @@ unZipStream = next where
|
||||
centralBody 0x06054b50 = EndOfCentralDirectory <$> endDirectory
|
||||
centralBody sig = fail $ "Unknown header signature: " ++ show sig
|
||||
fileHeader = do
|
||||
ver <- G.getWord16le
|
||||
G.getWord8 -- OS Version
|
||||
ver <- G.getWord8
|
||||
when (ver > zipVersion) $ fail $ "Unsupported version: " ++ show ver
|
||||
gpf <- G.getWord16le
|
||||
-- when (gpf .&. complement (bit 1 .|. bit 2 .|. bit 3) /= 0) $ fail $ "Unsupported flags: " ++ show gpf
|
||||
|
||||
@ -165,7 +165,8 @@ zipStream ZipOptions{..} = execStateC 0 $ do
|
||||
l64 = z64 ?* 16 + o64 ?* 8
|
||||
a64 = z64 || o64
|
||||
P.putWord32le 0x02014b50
|
||||
P.putWord16le zipVersion
|
||||
P.putWord8 osVersion
|
||||
P.putWord8 zipVersion
|
||||
P.putWord16le $ if a64 then 45 else 20
|
||||
common
|
||||
P.putWord32le crc
|
||||
@ -192,7 +193,8 @@ zipStream ZipOptions{..} = execStateC 0 $ do
|
||||
when z64 $ output $ do
|
||||
P.putWord32le 0x06064b50 -- zip64 end
|
||||
P.putWord64le 44 -- length of this record
|
||||
P.putWord16le zipVersion
|
||||
P.putWord8 osVersion
|
||||
P.putWord8 zipVersion
|
||||
P.putWord16le 45
|
||||
P.putWord32le 0 -- disk
|
||||
P.putWord32le 0 -- central disk
|
||||
|
||||
Loading…
Reference in New Issue
Block a user