Interpret version field according to spec

This commit is contained in:
Gregor Kleen 2017-10-17 14:16:07 +02:00
parent 5776d7bfaa
commit f1e610d48f
3 changed files with 14 additions and 7 deletions

View File

@ -1,5 +1,5 @@
module Codec.Archive.Zip.Conduit.Internal module Codec.Archive.Zip.Conduit.Internal
( zipVersion ( osVersion, zipVersion
, zipError , zipError
, idConduit , idConduit
, sizeCRC , sizeCRC
@ -15,14 +15,18 @@ import qualified Data.ByteString as BS
import qualified Data.Conduit as C import qualified Data.Conduit as C
import qualified Data.Conduit.Internal as CI import qualified Data.Conduit.Internal as CI
import Data.Digest.CRC32 (crc32Update) import Data.Digest.CRC32 (crc32Update)
import Data.Word (Word16, Word32, Word64) import Data.Word (Word8, Word16, Word32, Word64)
import Codec.Archive.Zip.Conduit.Types import Codec.Archive.Zip.Conduit.Types
-- |The version of this zip program, really just rough indicator of compatibility -- | The version of this zip program, really just rough indicator of compatibility
zipVersion :: Word16 zipVersion :: Word8
zipVersion = 48 zipVersion = 48
-- | The OS this implementation tries to be compatible to
osVersion :: Word8
osVersion = 0 -- DOS
zipError :: MonadThrow m => String -> m a zipError :: MonadThrow m => String -> m a
zipError = throwM . ZipError zipError = throwM . ZipError

View File

@ -151,7 +151,8 @@ unZipStream = next where
centralBody 0x06054b50 = EndOfCentralDirectory <$> endDirectory centralBody 0x06054b50 = EndOfCentralDirectory <$> endDirectory
centralBody sig = fail $ "Unknown header signature: " ++ show sig centralBody sig = fail $ "Unknown header signature: " ++ show sig
fileHeader = do fileHeader = do
ver <- G.getWord16le G.getWord8 -- OS Version
ver <- G.getWord8
when (ver > zipVersion) $ fail $ "Unsupported version: " ++ show ver when (ver > zipVersion) $ fail $ "Unsupported version: " ++ show ver
gpf <- G.getWord16le gpf <- G.getWord16le
-- when (gpf .&. complement (bit 1 .|. bit 2 .|. bit 3) /= 0) $ fail $ "Unsupported flags: " ++ show gpf -- when (gpf .&. complement (bit 1 .|. bit 2 .|. bit 3) /= 0) $ fail $ "Unsupported flags: " ++ show gpf

View File

@ -165,7 +165,8 @@ zipStream ZipOptions{..} = execStateC 0 $ do
l64 = z64 ?* 16 + o64 ?* 8 l64 = z64 ?* 16 + o64 ?* 8
a64 = z64 || o64 a64 = z64 || o64
P.putWord32le 0x02014b50 P.putWord32le 0x02014b50
P.putWord16le zipVersion P.putWord8 osVersion
P.putWord8 zipVersion
P.putWord16le $ if a64 then 45 else 20 P.putWord16le $ if a64 then 45 else 20
common common
P.putWord32le crc P.putWord32le crc
@ -192,7 +193,8 @@ zipStream ZipOptions{..} = execStateC 0 $ do
when z64 $ output $ do when z64 $ output $ do
P.putWord32le 0x06064b50 -- zip64 end P.putWord32le 0x06064b50 -- zip64 end
P.putWord64le 44 -- length of this record P.putWord64le 44 -- length of this record
P.putWord16le zipVersion P.putWord8 osVersion
P.putWord8 zipVersion
P.putWord16le 45 P.putWord16le 45
P.putWord32le 0 -- disk P.putWord32le 0 -- disk
P.putWord32le 0 -- central disk P.putWord32le 0 -- central disk