fix buffer length bug