[stdlib] String.index(before:): Fix index validation issues
[stdlib] String.index(before:): Fix index validation issues

`String.index(before:)` (and methods that rely on it, such as `Substring.index(before:)`, `.distance(from:to:)` etc.) does not currently verify that the given index falls before the `endIndex` before aligning it to a scalar boundary. This allows an out-of-bounds memory access when the provided index points to a position beyond the end of `self`’s storage.

Additionally, the `i > startIndex` check needs to be done after scalar alignment, not before, as alignment can round the index down to `startIndex`.

rdar://89497074&89495373

JGiola/swift,glessard/swift,apple/swift,JGiola/swift,roambotics/swift,JGiola/swift,ahoppen/swift,apple/swift,gregomni/swift,roambotics/swift,gregomni/swift,rudkx/swift,gregomni/swift,rudkx/swift,benlangmuir/swift,rudkx/swift,apple/swift,roambotics/swift,apple/swift,glessard/swift,glessard/swift,glessard/swift,benlangmuir/swift,benlangmuir/swift,ahoppen/swift,atrick/swift,glessard/swift,atrick/swift,JGiola/swift,roambotics/swift,gregomni/swift,apple/swift,JGiola/swift,glessard/swift,JGiola/swift,atrick/swift,ahoppen/swift,gregomni/swift,benlangmuir/swift,atrick/swift,rudkx/swift,roambotics/swift,atrick/swift,benlangmuir/swift,apple/swift,gregomni/swift,ahoppen/swift,ahoppen/swift,rudkx/swift,atrick/swift,roambotics/swift,rudkx/swift,ahoppen/swift,benlangmuir/swift