fix encode buf  length check bug