Fix bug overwriting the input stream buffer