Proposal (base): Add new Exp constructor to Text.Read.Lex.Lexeme

Gracjan Polak gracjanpolak at gmail.com
Fri Dec 9 09:01:59 CET 2011


Core of proposal: Add 

data Lexeme
  ...
  | Exp Integer Integer -- ^ Floating point literal in exponential form a*10^b

So that numbers in exponential notation can be represented directly.

Rationale:

Currently when parsing 12e1000000000000 it is at some point represented as
Rational, and of course does not fit in memory. Later on this Rational is
converted to Integer or Int8 or Float or Double, but we never get to that point.

This uncovers three bugs:
1) 12e12 :: Integer should not parse per Report
2) 12eXXX :: Double should parse, for large values of XXX should give +Infinity,
for large negative values of XXX should give +0.0
3) integer-gmp (and/or integer-simple) is not immune to allocation errors and
does 'Segmentation violation' or 'Bus error' (sometimes correctly throws 'Out of
memory' though)

My proposal addresses 1) and 2) as I needed to change public interface of
Text.Read.Lex to get it fixed.

More info and a patch in trac:

http://hackage.haskell.org/trac/ghc/ticket/5688

As reading numbers is core for web (for example HTTP headers, URLs, JSON etc)
this is a security issue.

As this is security issue I'm tempted to insist this goes into GHC 7.4. What do
you think?

Discussion period: 2 weeks, 25 Dec 2011.

-- 
Gracjan





More information about the Libraries mailing list