I may be misreading.. but it looks like if sizeInternal = MAXLENGTH above  (maxCsvSize) , then it can still hit this condition and throw error.