-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
GH-35095: [C++] Prevent write after close in arrow::ipc::IpcFormatWriter #37783
GH-35095: [C++] Prevent write after close in arrow::ipc::IpcFormatWriter #37783
Conversation
|
cpp/src/arrow/ipc/read_write_test.cc
Outdated
|
||
// Write after close raises status | ||
auto foo = writer_helper.WriteBatch(batch_ints); | ||
// ASSERT_RAISES(Invalid, writer_helper.WriteBatch(batch_ints)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this assertion commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops. An extremely embarrassing mistake. Thank you for catching it. It's been fixed.
@@ -1070,6 +1070,9 @@ class ARROW_EXPORT IpcFormatWriter : public RecordBatchWriter { | |||
Status WriteRecordBatch( | |||
const RecordBatch& batch, | |||
const std::shared_ptr<const KeyValueMetadata>& custom_metadata) override { | |||
if (closed_) { | |||
return Status::Invalid("Destination already closed"); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need similar check in WriteTable
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question.
It appears that WriteTable ultimately calls WriteRecordBatch. This appears to be documented as well, in that the documentation for RecordBatchWriter::WriteTable is that a a table is written by creating a sequence of record batches. So testing WriteTable doesn't seem to be necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
@@ -1070,6 +1070,9 @@ class ARROW_EXPORT IpcFormatWriter : public RecordBatchWriter { | |||
Status WriteRecordBatch( | |||
const RecordBatch& batch, | |||
const std::shared_ptr<const KeyValueMetadata>& custom_metadata) override { | |||
if (closed_) { | |||
return Status::Invalid("Destination already closed"); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I see.
|
Could you check the "C++ / AMD64 Ubuntu 22.04 C++ ASAN UBSAN" failure?
|
c1754fe
to
85f3916
Compare
Yep, taking a look. Rebasing on main first, in case it was fixed elsewhere. |
This addresses apacheGH-35095 by adding a flag to IpcFormatWriter to track when a writer has been closed, and check this flag before writes.
85f3916
to
ae6e0fa
Compare
Oh, the failure has gone. |
After merging your PR, Conbench analyzed the 6 benchmarking runs that have been run so far on merge-commit 6cd34f3. There were no benchmark performance regressions. 🎉 The full Conbench report has more details. It also includes information about possible false positives for unstable benchmarks that are known to sometimes produce them. |
…matWriter (apache#37783) This addresses apacheGH-35095 by adding a flag to IpcFormatWriter to track when a writer has been closed, and check this flag before writes. ### Rationale for this change This addresses apache#35095 , preventing stream and file IPC writers from writing record batches once the IPC writer has been closed. ### What changes are included in this PR? Adding a flag so that an IpcFormatWriter to track when it's been closed, a check before writes in IpcFormatWriter, and two tests to confirm it works as expected. ### Are these changes tested? Yes, the changes are tested. The two tests were added, and the C++ test suite ran. No unexpected failures appeared. ### Are there any user-facing changes? Other than newly returning an invalid status when writing after close, no, there should not be any user-facing changes. * Closes: apache#35095 Lead-authored-by: Chris Jordan-Squire <[email protected]> Co-authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
…matWriter (apache#37783) This addresses apacheGH-35095 by adding a flag to IpcFormatWriter to track when a writer has been closed, and check this flag before writes. ### Rationale for this change This addresses apache#35095 , preventing stream and file IPC writers from writing record batches once the IPC writer has been closed. ### What changes are included in this PR? Adding a flag so that an IpcFormatWriter to track when it's been closed, a check before writes in IpcFormatWriter, and two tests to confirm it works as expected. ### Are these changes tested? Yes, the changes are tested. The two tests were added, and the C++ test suite ran. No unexpected failures appeared. ### Are there any user-facing changes? Other than newly returning an invalid status when writing after close, no, there should not be any user-facing changes. * Closes: apache#35095 Lead-authored-by: Chris Jordan-Squire <[email protected]> Co-authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
…matWriter (apache#37783) This addresses apacheGH-35095 by adding a flag to IpcFormatWriter to track when a writer has been closed, and check this flag before writes. ### Rationale for this change This addresses apache#35095 , preventing stream and file IPC writers from writing record batches once the IPC writer has been closed. ### What changes are included in this PR? Adding a flag so that an IpcFormatWriter to track when it's been closed, a check before writes in IpcFormatWriter, and two tests to confirm it works as expected. ### Are these changes tested? Yes, the changes are tested. The two tests were added, and the C++ test suite ran. No unexpected failures appeared. ### Are there any user-facing changes? Other than newly returning an invalid status when writing after close, no, there should not be any user-facing changes. * Closes: apache#35095 Lead-authored-by: Chris Jordan-Squire <[email protected]> Co-authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
…matWriter (apache#37783) This addresses apacheGH-35095 by adding a flag to IpcFormatWriter to track when a writer has been closed, and check this flag before writes. ### Rationale for this change This addresses apache#35095 , preventing stream and file IPC writers from writing record batches once the IPC writer has been closed. ### What changes are included in this PR? Adding a flag so that an IpcFormatWriter to track when it's been closed, a check before writes in IpcFormatWriter, and two tests to confirm it works as expected. ### Are these changes tested? Yes, the changes are tested. The two tests were added, and the C++ test suite ran. No unexpected failures appeared. ### Are there any user-facing changes? Other than newly returning an invalid status when writing after close, no, there should not be any user-facing changes. * Closes: apache#35095 Lead-authored-by: Chris Jordan-Squire <[email protected]> Co-authored-by: Sutou Kouhei <[email protected]> Signed-off-by: Sutou Kouhei <[email protected]>
This addresses GH-35095 by adding a flag to IpcFormatWriter to track when a writer has been closed, and check this flag before writes.
Rationale for this change
This addresses #35095 , preventing stream and file IPC writers from writing record batches once the IPC writer has been closed.
What changes are included in this PR?
Adding a flag so that an IpcFormatWriter to track when it's been closed, a check before writes in IpcFormatWriter, and two tests to confirm it works as expected.
Are these changes tested?
Yes, the changes are tested. The two tests were added, and the C++ test suite ran. No unexpected failures appeared.
Are there any user-facing changes?
Other than newly returning an invalid status when writing after close, no, there should not be any user-facing changes.