Skip to content

Commit

Permalink
update with bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
emilypi committed Dec 7, 2023
1 parent a0bf93d commit be88bcc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 28 deletions.
4 changes: 2 additions & 2 deletions base64.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ library
Data.ByteString.Base64.Internal.W64.Loop

build-depends:
base >=4.14 && <4.19
base >=4.14 && <4.19
, bytestring ^>=0.11
, deepseq >=1.4.8.0 && <1.5
, deepseq >=1.4.4 && <1.5
, text ^>=2.0
, text-short ^>=0.1

Expand Down
18 changes: 12 additions & 6 deletions benchmarks/Base64Bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,33 @@ main =
bgroup "decode"
[ bgroup "25"
[ bench "base64-bytestring" $ whnf Bos.decode (B64.extractBase64 bs25)
, bench "base64" $ whnf B64.decodeBase64 bs25
, bench "base64-typed" $ whnf B64.decodeBase64 bs25
, bench "base64-untyped" $ whnf B64.decodeBase64Untyped (B64.extractBase64 bs25)
]
, bgroup "100"
[ bench "base64-bytestring" $ whnf Bos.decode (B64.extractBase64 bs100)
, bench "base64" $ whnf B64.decodeBase64 bs100
, bench "base64-typed" $ whnf B64.decodeBase64 bs100
, bench "base64-untyped" $ whnf B64.decodeBase64Untyped (B64.extractBase64 bs100)
]
, bgroup "1k"
[ bench "base64-bytestring" $ whnf Bos.decode (B64.extractBase64 bs1k)
, bench "base64" $ whnf B64.decodeBase64 bs1k
, bench "base64-typed" $ whnf B64.decodeBase64 bs1k
, bench "base64-untyped" $ whnf B64.decodeBase64Untyped (B64.extractBase64 bs1k)
]
, bgroup "10k"
[ bench "base64-bytestring" $ whnf Bos.decode (B64.extractBase64 bs10k)
, bench "base64" $ whnf B64.decodeBase64 bs10k
, bench "base64-typed" $ whnf B64.decodeBase64 bs10k
, bench "base64-untyped" $ whnf B64.decodeBase64Untyped (B64.extractBase64 bs10k)
]
, bgroup "100k"
[ bench "base64-bytestring" $ whnf Bos.decode (B64.extractBase64 bs100k)
, bench "base64" $ whnf B64.decodeBase64 bs100k
, bench "base64-typed" $ whnf B64.decodeBase64 bs100k
, bench "base64-untyped" $ whnf B64.decodeBase64Untyped (B64.extractBase64 bs100k)
]
, bgroup "1mm"
[ bench "base64-bytestring" $ whnf Bos.decode (B64.extractBase64 bs1mm)
, bench "base64" $ whnf B64.decodeBase64 bs1mm
, bench "base64-typed" $ whnf B64.decodeBase64 bs1mm
, bench "base64-untyped" $ whnf B64.decodeBase64Untyped (B64.extractBase64 bs1mm)
]
]
]
Expand Down
2 changes: 1 addition & 1 deletion src/Data/ByteString/Base64/Internal/W64/Loop.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ innerLoop
innerLoop !etable !sptr !dptr !end finish = go sptr dptr
where
go !src !dst
| plusPtr src 5 >= end =
| plusPtr src 7 >= end =
W16.innerLoop etable (castPtr src) (castPtr dst) (castPtr end) finish
| otherwise = do
!t <- peekWord64BE src
Expand Down
38 changes: 19 additions & 19 deletions test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -387,29 +387,29 @@ offsetVectors :: (IsString a, Eq a, Show a) => Harness a -> TestTree
offsetVectors Harness{..} = testGroup "Offset tests"
[ testGroup "Invalid padding"
[ testCase "Invalid staggered padding" $ do
decodeUrl "=A==" @=? Left "invalid padding at offset: 0"
decodeUrl "P===" @=? Left "invalid padding at offset: 1"
decodeUrl "=A==" @=? Left "invalid padding near offset: 0"
decodeUrl "P===" @=? Left "invalid padding near offset: 1"
, testCase "Invalid character coverage - final chunk" $ do
decodeUrl "%D==" @=? Left "invalid character at offset: 0"
decodeUrl "P%==" @=? Left "invalid character at offset: 1"
decodeUrl "PD%=" @=? Left "invalid character at offset: 2"
decodeUrl "PA=%" @=? Left "invalid character at offset: 3"
decodeUrl "PDw%" @=? Left "invalid character at offset: 3"
decodeUrl "%D==" @=? Left "invalid base64 encoding near offset: 0"
decodeUrl "P%==" @=? Left "invalid base64 encoding near offset: 1"
decodeUrl "PD%=" @=? Left "invalid base64 encoding near offset: 2"
decodeUrl "PA=%" @=? Left "invalid base64 encoding near offset: 3"
decodeUrl "PDw%" @=? Left "invalid base64 encoding near offset: 3"
, testCase "Invalid character coverage - decode chunk" $ do
decodeUrl "%Dw_PDw_" @=? Left "invalid character at offset: 0"
decodeUrl "P%w_PDw_" @=? Left "invalid character at offset: 1"
decodeUrl "PD%_PDw_" @=? Left "invalid character at offset: 2"
decodeUrl "PDw%PDw_" @=? Left "invalid character at offset: 3"
decodeUrl "%Dw_PDw_" @=? Left "invalid base64 encoding near offset: 0"
decodeUrl "P%w_PDw_" @=? Left "invalid base64 encoding near offset: 1"
decodeUrl "PD%_PDw_" @=? Left "invalid base64 encoding near offset: 2"
decodeUrl "PDw%PDw_" @=? Left "invalid base64 encoding near offset: 3"
, testCase "Invalid padding in body" $ do
decodeUrl "PD=_PDw_" @=? Left "invalid padding at offset: 2"
decodeUrl "PDw=PDw_" @=? Left "invalid padding at offset: 3"
decodeUrl "PD=_PDw_" @=? Left "invalid padding near offset: 2"
decodeUrl "PDw=PDw_" @=? Left "invalid padding near offset: 3"
, testCase "Padding fails everywhere but end" $ do
decode "=eAoeAo=" @=? Left "invalid padding at offset: 0"
decode "e=AoeAo=" @=? Left "invalid padding at offset: 1"
decode "eA=oeAo=" @=? Left "invalid padding at offset: 2"
decode "eAo=eAo=" @=? Left "invalid padding at offset: 3"
decode "eAoe=Ao=" @=? Left "invalid padding at offset: 4"
decode "eAoeA=o=" @=? Left "invalid padding at offset: 5"
decode "=eAoeAo=" @=? Left "invalid padding near offset: 0"
decode "e=AoeAo=" @=? Left "invalid padding near offset: 1"
decode "eA=oeAo=" @=? Left "invalid padding near offset: 2"
decode "eAo=eAo=" @=? Left "invalid padding near offset: 3"
decode "eAoe=Ao=" @=? Left "invalid padding near offset: 4"
decode "eAoeA=o=" @=? Left "invalid padding near offset: 5"
]
]

Expand Down

0 comments on commit be88bcc

Please sign in to comment.