don't index outside of the path (closes #22312)

--HG--
branch : 2.7
extra : amend_source : ea7444e10ff782f3d4222638f28eafdf8d2f1015