Fixed writes/reads based on improper buffer size and array length values