fix heap buffer overflow