Fix possible buffer overflow.

(cherry picked from commit 47a131871720268f2162278d915404d65052d9c8)