add buffer length check.