From 3270e03da1097f8054e12c1d1e5fa5408a91be7b Mon Sep 17 00:00:00 2001 From: Henning Guenther Date: Thu, 26 Feb 2009 06:46:53 -0800 Subject: [PATCH] Made decoding array lookup safe Ignore-this: 346535974ae363daf4ade7e22ed48ad7 darcs-hash:20090226144653-a4fee-42808f15a3bab3fa1712ab12d8b0cfb54ff96aad --- Data/Encoding/Base.hs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Data/Encoding/Base.hs b/Data/Encoding/Base.hs index f4318aa..8b03007 100644 --- a/Data/Encoding/Base.hs +++ b/Data/Encoding/Base.hs @@ -76,7 +76,11 @@ decodeWithArray2 :: ByteSource m => UArray (Word8,Word8) Int -> m Char decodeWithArray2 arr = do w1 <- fetchWord8 w2 <- fetchWord8 - let res = arr!(w1,w2) - if res < 0 - then throwException $ IllegalCharacter w1 - else return $ chr res \ No newline at end of file + if inRange (bounds arr) (w1,w2) + then (do + let res = arr!(w1,w2) + if res < 0 + then throwException $ IllegalCharacter w1 + else return $ chr res + ) + else throwException $ IllegalCharacter w1 \ No newline at end of file