#2120: Arrays allow out-of-bounds indexes
-------------------------+--------------------------------------------------
Reporter: amthrax | Owner:
Type: bug | Status: new
Priority: normal | Component: libraries (other)
Version: 6.8.2 | Severity: normal
Keywords: | Testcase:
Architecture: Multiple | Os: Multiple
-------------------------+--------------------------------------------------
The array changes proposed and recently implemented for ticket #1610 (Make
arrays safer) strengthened the requirements on `Ix` instances, but
weakened the requirements on array users. Specifically, array referencing
now permits indexes that are ''not'' `inRange`.
For example,
{{{
import Data.Array.IArray
b :: Array (Int,Int) Int
b = listArray ((0,0), (3,3)) (repeat 0)
main = do
print (b ! (0,5)) -- SHOULD fail, but doesn't
print (index (bounds b) (0,5)) -- DOES fail
}}}
The first line in `main` ''should'' fail because the specified index is
not `inRange`, but doesn't because the `(!)` operator (specifically
`Data.Array.Base.safeIndex`) now uses `unsafeIndex` and simply checks that
the resulting index is within the linearized bounds of the array. In this
case, the unsafe index of (0,5) wraps aroung to the index of (1,1).
A simple fix would be to use `index` instead of `unsafeIndex` in the
implementation of `Data.Array.Base.safeIndex`. This would both require
the user to use in-bounds references and would require `Ix` instances to
return in-bounds indexes.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2120>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs