check string bounds

Change-Id: I92f2dbbe12956ee9432d592851f10bceaa5ce25d
(cherry picked from commit 4e75f724cc59d457cdd905c68666633e3b2612f4)