Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARROW-15626: [GLib] Fix a bug that GArrowGIOInputStream may not read enough data #12380

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions c_glib/arrow-glib/input-stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -802,17 +802,19 @@ namespace garrow {
arrow::Result<int64_t> Read(int64_t n_bytes, void *out) override {
std::lock_guard<std::mutex> guard(lock_);
GError *error = NULL;
auto n_read_bytes = g_input_stream_read(input_stream_,
out,
n_bytes,
NULL,
&error);
if (n_read_bytes == -1) {
gsize n_read_bytes = 0;
auto success = g_input_stream_read_all(input_stream_,
out,
n_bytes,
&n_read_bytes,
NULL,
&error);
if (success) {
return n_read_bytes;
} else {
return garrow_error_to_status(error,
arrow::StatusCode::IOError,
"[gio-input-stream][read]");
} else {
return n_read_bytes;
}
}

Expand All @@ -833,20 +835,22 @@ namespace garrow {

std::lock_guard<std::mutex> guard(lock_);
GError *error = NULL;
auto n_read_bytes = g_input_stream_read(input_stream_,
buffer->mutable_data(),
n_bytes,
NULL,
&error);
if (n_read_bytes == -1) {
return garrow_error_to_status(error,
arrow::StatusCode::IOError,
"[gio-input-stream][read][buffer]");
} else {
if (n_read_bytes < n_bytes) {
gsize n_read_bytes = 0;
auto success = g_input_stream_read_all(input_stream_,
buffer->mutable_data(),
n_bytes,
&n_read_bytes,
NULL,
&error);
if (success) {
if (n_read_bytes < static_cast<gsize>(n_bytes)) {
RETURN_NOT_OK(buffer->Resize(n_read_bytes));
}
return std::move(buffer);
} else {
return garrow_error_to_status(error,
arrow::StatusCode::IOError,
"[gio-input-stream][read][buffer]");
}
}

Expand Down