git.iko.soy/typeable/attoparsec
on master help sign in
Make the double and number parsers safe against DoS attacks
commitce97ed1258f3c0b85bd6f8c51115e4ea6525d410 authorBas van Dijk <v.dijk.bas@gmail.com> dateThu 15 May 2014, 14:07 (12 years ago) parent613f166
3 files changed+13−13
Data/Attoparsec/ByteString/Char8.hs+6−6 Data/Attoparsec/Text.hs+6−6 attoparsec.cabal+1−1
Data/Attoparsec/ByteString/Char8.hs+6−6
@@ -133,8 +133,8 @@ import Data.Bits (Bits, (.|.), shiftL)
133133import Data.ByteString.Internal (c2w, w2c)
134134import Data.Int (Int8, Int16, Int32, Int64)
135135import Data.String (IsString(..))
136−import Data.Scientific (Scientific, coefficient, base10Exponent)
137−import qualified Data.Scientific as Sci (scientific)
136+import Data.Scientific (Scientific)
137+import qualified Data.Scientific as Sci
138138import Data.Word (Word8, Word16, Word32, Word64, Word)
139139import Prelude hiding (takeWhile)
140140import qualified Data.Attoparsec.ByteString as A
@@ -524,7 +524,7 @@ rational = scientifically realToFrac
524524-- This function does not accept string representations of \"NaN\" or
525525-- \"Infinity\".
526526double :: Parser Double
527−double = rational
527+double = scientifically Sci.toRealFloat
528528
529529-- | Parse a number, attempting to preserve both speed and precision.
530530--
@@ -539,11 +539,11 @@ double = rational
539539-- \"
540540number :: Parser Number
541541number = scientifically $ \s ->
542− let e = base10Exponent s
543− c = coefficient s
542+ let e = Sci.base10Exponent s
543+ c = Sci.coefficient s
544544 in if e >= 0
545545 then I (c * 10 ^ e)
546− else D (fromInteger c / 10 ^ negate e)
546+ else D (Sci.toRealFloat s)
547547
548548-- | Parse a scientific number.
549549--
Data/Attoparsec/Text.hs+6−6
@@ -124,8 +124,8 @@ module Data.Attoparsec.Text
124124import Control.Applicative (pure, (<$>), (*>), (<*), (<|>))
125125import Data.Attoparsec.Combinator
126126import Data.Attoparsec.Number (Number(..))
127−import Data.Scientific (Scientific, coefficient, base10Exponent)
128−import qualified Data.Scientific as Sci (scientific)
127+import Data.Scientific (Scientific)
128+import qualified Data.Scientific as Sci
129129import Data.Attoparsec.Text.Internal (Parser, Result, parse, takeWhile1)
130130import Data.Bits (Bits, (.|.), shiftL)
131131import Data.Char (isAlpha, isDigit, isSpace, ord)
@@ -373,7 +373,7 @@ rational = scientifically realToFrac
373373-- This function does not accept string representations of \"NaN\" or
374374-- \"Infinity\".
375375double :: Parser Double
376−double = rational
376+double = scientifically Sci.toRealFloat
377377
378378-- | Parse a number, attempting to preserve both speed and precision.
379379--
@@ -388,11 +388,11 @@ double = rational
388388-- \"Infinity\".
389389number :: Parser Number
390390number = scientifically $ \s ->
391− let e = base10Exponent s
392− c = coefficient s
391+ let e = Sci.base10Exponent s
392+ c = Sci.coefficient s
393393 in if e >= 0
394394 then I (c * 10 ^ e)
395− else D (fromInteger c / 10 ^ negate e)
395+ else D (Sci.toRealFloat s)
396396
397397-- | Parse a scientific number.
398398--
attoparsec.cabal+1−1
@@ -44,7 +44,7 @@ library
4444 containers,
4545 deepseq,
4646 text >= 0.11.3.1,
47− scientific >= 0.2
47+ scientific >= 0.3.1
4848
4949 exposed-modules: Data.Attoparsec
5050 Data.Attoparsec.ByteString