fix read / write bug for not completely r/w given buffer