BUG: Fix Index.putmask makes stack overflow with an invalid mask
- [x] closes #18368
- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [x] whatsnew entry
