Skip to content

Commit

Permalink
Check for overflow in getLength
Browse files Browse the repository at this point in the history
  • Loading branch information
enolan committed Jun 6, 2016
1 parent 29665b8 commit 2734638
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions encoding/Data/ASN1/Serialize.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
-- Stability : experimental
-- Portability : unknown
--
{-# Language ScopedTypeVariables #-}
module Data.ASN1.Serialize (getHeader, putHeader) where

import qualified Data.ByteString as B
Expand Down Expand Up @@ -59,8 +60,13 @@ getLength = do
then case clearBit l1 7 of
0 -> return LenIndefinite
len -> do
lw <- getBytes len
return (LenLong len $ uintbs lw)
let maxBytes' :: Double =
logBase 2 (fromIntegral (maxBound :: Int)) / 8
maxBytes :: Int = floor maxBytes'
if len <= maxBytes
then do lw <- getBytes len
return $ LenLong len $ uintbs lw
else fail "invalid length - would overflow"
else
return (LenShort l1)
where
Expand Down

0 comments on commit 2734638

Please sign in to comment.