Fix buffer overflows am: 0da62f4818 am: a389af217e
am: a9b9a33d76

Change-Id: I30ebd4a6b86d66a6e4849a2a3e14f3be0bc4c494