r2.11 cherry-pick: ee004b18b97 "Add out of bounds array check to dynamic_stitch_op."
Refer to the original commit: https://github.com/tensorflow/tensorflow/commit/ee004b18b976eeb5a758020af8880236cd707d05