Skip to content

Numeric types’ Read instances use exponential CPU/memory

Computing

read "1e99999999" :: Int -- returns 0 read "1e99999999" :: Integer -- returns [REDACTED] read "1e99999999" :: Float -- returns Infinity read "1e99999999" :: Double -- returns Infinity

takes rather a lot of CPU time and memory, and adding more digits to the exponent makes it take exponentially more. In some applications, this behavior could be exploitable as a denial of service.

I’m not sure what the right solution is for Integer, but clearly all the other cases should be optimized to produce 0 or Infinity very quickly.

Trac metadata
Trac field Value
Version 7.4.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/base
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information