When String#index and String#byteindex are called with Regexp and offset they clear $~ (that contains result of the last Regexp matching) when offset < -size. But they don't clear $~ when offset > size what seems inconsistent:
Backport changed from 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN to 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: DONTNEED
The issue doesn't affect 3.3 and master. It appears fixed by 9dcdffb8bf8a3654fd78bf1a58b30c8e13888a7a. If you would like the fix backported to 3.2, please respond.