Twinside / Rasterific

A drawing engine in Haskell
BSD 3-Clause "New" or "Revised" License
140 stars 11 forks source link

resource exhaustion on bad Float values like Infinity #26

Closed claudeha closed 7 years ago

claudeha commented 7 years ago

This small example quickly uses many GB RAM (seemingly unbounded) without doing anything useful. Better would be to bail out early with an exception (perhaps Overflow :: ArithException ? not sure which is best). I also expect bad behaviour from NaN but i haven't explicitly tested yet.

import Codec.Picture( PixelRGBA8( .. ), writePng )
import Graphics.Rasterific
import Graphics.Rasterific.Texture

main :: IO ()
main = do
  let white = PixelRGBA8 255 255 255 255
      drawColor = PixelRGBA8 0 0x86 0xc1 255
      img = renderDrawing 400 200 white $
         withTexture (uniformTexture drawColor) $ do
            fill $ circle (V2 0 0) 1e50 -- overflows to Infinity :: Float -> boom
  writePng "bug.png" img
Twinside commented 7 years ago

Ok, the circle function creates bezier curve approximation of a circle, and is yielding NaN in the process. Will fix asap.