Fix possible out of bounds accesses

Bug: 30074856
Change-Id: I1a1387ed29d2e0d010b0d5d4bb3d29453a3a7666
(cherry picked from commit ee54e6ceb66e16b3c10c4a9fc8fbe5fff9110b62)
(cherry picked from commit 78cc5b2401047d8c8ca77f633d8fa32c94e8e8f5)
2 files changed