check buf.length