Commits


mwish authored and GitHub committed 7d5a8186a51
GH-43949: [C++] io::BufferedInput: Fix invalid state after SetBufferSize (#44387) ### Rationale for this change See https://github.com/apache/arrow/issues/43949 The problem is `Peek` and `Read` both calls `SetBufferSize`, however: 1. `Read` implicit says that, when `SetBufferSize` or read, the previous buffer is not being required. In this scenerio, `bytes_buffered_` is always 0, since `Read` will consume all data. And `new_buffer_size == std::min(new_buffer_size, (raw_read_bound_ - raw_read_total_))` 2. `Peek` still requires the buffer-size here. So, `bytes_buffered_` might not 0. When `Peek`, the `new_buffer_size` would less than expected, which shrinks the buffer ### What changes are included in this PR? Update the Logic of `SetBufferSize` 1. If `bytes_buffered_ == 0`, `SetBufferSize` can discard the current buffer 2. Otherwise, `SetBufferSize` should resize minimal to `buffer_size_ + (raw_read_bound_ - raw_read_total_)`, since it should considering the current buffer ### Are these changes tested? Yes ### Are there any user-facing changes? Bugfix * GitHub Issue: #43949 Lead-authored-by: mwish <maplewish117@gmail.com> Co-authored-by: mwish <1506118561@qq.com> Co-authored-by: Antoine Pitrou <pitrou@free.fr> Signed-off-by: Antoine Pitrou <antoine@python.org>