Add bounds checking to DomainIndex. Fixes #3599.
Merge pull request #3628 from pchote/domain-crash

Fix out-of-bounds crash in DomainIndex.