Source

{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-}-- Regression tests for specific bugs.importControl.Exception(SomeException,handle)importSystem.IOimportqualifiedData.ByteStringasBimportqualifiedData.ByteString.LazyasLBimportqualifiedData.TextasTimportqualifiedData.Text.IOasTimportqualifiedData.Text.LazyasLTimportqualifiedData.Text.Lazy.EncodingasLEimportqualifiedTest.FrameworkasFimportqualifiedTest.Framework.Providers.HUnitasFimportTest.HUnit(assertFailure)importTestUtils(withTempFile)-- Reported by Michael Snoyman: UTF-8 encoding a large lazy bytestring-- caused either a segfault or attempt to allocate a negative number-- of bytes.lazy_encode_crash=withTempFile$\_h->LB.hPuth.LE.encodeUtf8.LT.pack.replicate100000$'a'-- Reported by Pieter Laeremans: attempting to read an incorrectly-- encoded file can result in a crash in the RTS (i.e. not merely an-- exception).hGetContents_crash=withTempFile$\pathh->doB.hPuth(B.pack[0x78,0xc4,0x0a])>>hClosehh'<-openFilepathReadModehSetEncodingh'utf8handle(\(_::SomeException)->return())$T.hGetContentsh'>>assertFailure"T.hGetContents should crash"-- Reported by Ian Lynagh: attempting to allocate a sufficiently large-- string (via either Array.new or Text.replicate) could result in an-- integer overflow.replicate_crash=handle(\(_::SomeException)->return())$T.replicate(2^power)"0123456789abcdef"`seq`assertFailure"T.replicate should crash"wherepower|maxBound==(2147483647::Int)=28|otherwise=60::Inttests::F.Testtests=F.testGroup"crashers"[F.testCase"hGetContents_crash"hGetContents_crash,F.testCase"lazy_encode_crash"lazy_encode_crash,F.testCase"replicate_crash"replicate_crash]main=F.defaultMain[tests]