Skip to content

Commit 73741a3

Browse files
committed
fix
1 parent 6180908 commit 73741a3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

cpp/src/arrow/io/buffered.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,14 @@ class BufferedInputStream::Impl : public BufferedBase {
297297
new_buffer_size, ", buffer_pos: ", buffer_pos_,
298298
", bytes_buffered: ", bytes_buffered_, ", buffer_size: ", buffer_size_);
299299
}
300+
bool need_reset_buffer_pos = false;
300301
if (raw_read_bound_ >= 0) {
301302
// No need to reserve space for more than the total remaining number of bytes.
302303
if (bytes_buffered_ == 0) {
303-
// Special case: we can not keep the current buffer because it does not
304+
// Special case: we can override data in the current buffer because it does not
304305
// contain any required data.
305306
new_buffer_size = std::min(new_buffer_size, raw_read_bound_ - raw_read_total_);
307+
need_reset_buffer_pos = true;
306308
} else {
307309
// We should keep the current buffer because it contains data that
308310
// can be read.
@@ -311,7 +313,11 @@ class BufferedInputStream::Impl : public BufferedBase {
311313
buffer_pos_ + bytes_buffered_ + (raw_read_bound_ - raw_read_total_));
312314
}
313315
}
314-
return ResizeBuffer(new_buffer_size);
316+
auto status = ResizeBuffer(new_buffer_size);
317+
if (status.ok() && need_reset_buffer_pos) {
318+
buffer_pos_ = 0;
319+
}
320+
return status;
315321
}
316322

317323
Result<std::string_view> Peek(int64_t nbytes) {

0 commit comments

Comments
 (0)