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

GH-41407: [C++] Use static method to fill scalar scratch space to prevent ub #41421

Merged
merged 6 commits into from
Apr 30, 2024

Conversation

zanmato1984
Copy link
Collaborator

@zanmato1984 zanmato1984 commented Apr 28, 2024

Rationale for this change

In #40237, I introduced scalar scratch space filling in concrete scalar sub-class constructor, in which there is a static down-casting of this to sub-class pointer. Though this is common in CRTP, it happens in base cast constructor. And this is reported in #41407 to be UB by UBSAN's "vptr" sanitizing.

I'm not a language lawyer to tell if this is a true/false-positive. So I proposed two approaches:

  1. The easy way: add suppression in [1], like we already did for shared_ptr. But apparently this won't be feasible if this is a true-positive (need some language lawyer's help to confirm).
  2. The hard way: totally avoid this so-to-speak UB but may introduce more boilerplate code. This PR is the hard way.

[1] https://github.com/apache/arrow/blob/main/r/tools/ubsan.supp

What changes are included in this PR?

Make FillScratchSpace static.

Are these changes tested?

The existing UT should cover it well.

Are there any user-facing changes?

None.

Copy link

⚠️ GitHub issue #41407 has been automatically assigned in GitHub to PR creator.

@jonkeane
Copy link
Member

@github-actions crossbow submit test-fedore-r-clang-sanitizer test-ubuntu-r-sanitizer

Copy link

Unable to match any tasks for `test-fedore-r-clang-sanitizer`
The Archery job run can be found at: https://github.com/apache/arrow/actions/runs/8868210807

@jonkeane
Copy link
Member

@github-actions crossbow submit test-fedora-r-clang-sanitizer test-ubuntu-r-sanitizer

Copy link

Revision: 0f85a7b

Submitted crossbow builds: ursacomputing/crossbow @ actions-b62c1c107c

Task Status
test-fedora-r-clang-sanitizer GitHub Actions
test-ubuntu-r-sanitizer GitHub Actions

jonkeane added a commit that referenced this pull request Apr 29, 2024
….4 cleanups (#41403)

### Rationale for this change

Keep up with the state of the world, ensure we are maintaining backwards compatibility.

Resolves #41402

### What changes are included in this PR?

* Bump to 4.4 as the release
* Remove old 3.6 jobs now that we no longer support that; clean up code where we hardcode things fro 3.6 and below
* Move many of our CI jobs to [rhub's new containers](https://github.com/r-hub/containers). We were accidentally running stale R devel (from December 2023) because the other rhub images stopped being updated. (One exception to be done as a follow on: #41416)
* Resolve a number of extended test failures

With this PR R extended tests should be all green with the exceptions of:

* Two sanitizer jobs (test-fedora-r-clang-sanitizer, test-ubuntu-r-sanitizer) — which are being investigated / fixed in #41421
* Valgrind — I'm running one last run with a new suppression file. 
* Binary jobs — these work but fail at upload, see #41403 (comment)
* Windows R Release — failing on main, #41398

### Are these changes tested?

By definition.

### Are there any user-facing changes?

No.

* GitHub Issue: #41402

Lead-authored-by: Jonathan Keane <jkeane@gmail.com>
Co-authored-by: Jacob Wujciak-Jens <jacob@wujciak.de>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
raulcd pushed a commit that referenced this pull request Apr 29, 2024
….4 cleanups (#41403)

### Rationale for this change

Keep up with the state of the world, ensure we are maintaining backwards compatibility.

Resolves #41402

### What changes are included in this PR?

* Bump to 4.4 as the release
* Remove old 3.6 jobs now that we no longer support that; clean up code where we hardcode things fro 3.6 and below
* Move many of our CI jobs to [rhub's new containers](https://github.com/r-hub/containers). We were accidentally running stale R devel (from December 2023) because the other rhub images stopped being updated. (One exception to be done as a follow on: #41416)
* Resolve a number of extended test failures

With this PR R extended tests should be all green with the exceptions of:

* Two sanitizer jobs (test-fedora-r-clang-sanitizer, test-ubuntu-r-sanitizer) — which are being investigated / fixed in #41421
* Valgrind — I'm running one last run with a new suppression file. 
* Binary jobs — these work but fail at upload, see #41403 (comment)
* Windows R Release — failing on main, #41398

### Are these changes tested?

By definition.

### Are there any user-facing changes?

No.

* GitHub Issue: #41402

Lead-authored-by: Jonathan Keane <jkeane@gmail.com>
Co-authored-by: Jacob Wujciak-Jens <jacob@wujciak.de>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
@jorisvandenbossche
Copy link
Member

@github-actions crossbow submit test-ubuntu-22.04-cpp-emscripten

@jorisvandenbossche
Copy link
Member

(ignore my crossbow trigger, this PR is not going to fix that)

Copy link

Revision: 0f85a7b

Submitted crossbow builds: ursacomputing/crossbow @ actions-87bb998c79

Task Status
test-ubuntu-22.04-cpp-emscripten GitHub Actions

@bkietz bkietz self-requested a review April 30, 2024 15:45
Copy link
Member

@bkietz bkietz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this approach is preferable to a suppression, LGTM.

Comment on lines +298 to +300
BinaryScalar(std::string s, std::shared_ptr<DataType> type)
: BaseBinaryScalar(std::move(s), std::move(type)),
ArraySpanFillFromScalarScratchSpace(this->value) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, from my read I think this was actually UB because base class constructors run first. For example in the case of BinaryScalar, the constructor for ArraySpanFillFromScalarScratchSpace<BinaryScalar> ran first and downcast itself to a BinaryScalar which hadn't been constructed yet. The way you have it written now, BaseBinaryScalar will be constructed (including its value) before ArraySpanFillFromScalarScratchSpace references it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I agree. Thank you for the elaboration.

cpp/src/arrow/scalar.cc Outdated Show resolved Hide resolved
cpp/src/arrow/scalar.cc Outdated Show resolved Hide resolved
@github-actions github-actions bot added awaiting changes Awaiting changes and removed awaiting review Awaiting review labels Apr 30, 2024
zanmato1984 and others added 2 commits May 1, 2024 00:35
Co-authored-by: Benjamin Kietzman <bengilgit@gmail.com>
Co-authored-by: Benjamin Kietzman <bengilgit@gmail.com>
@github-actions github-actions bot added awaiting change review Awaiting change review and removed awaiting changes Awaiting changes labels Apr 30, 2024
@zanmato1984
Copy link
Collaborator Author

Comments addressed. PTAL @bkietz . And would you please help to trigger test-fedora-r-clang-sanitizer and test-ubuntu-r-sanitizer CI tasks? I want to make sure the updated change still pass them. Thank you!

@jonkeane
Copy link
Member

@github-actions crossbow submit test-fedora-r-clang-sanitizer test-ubuntu-r-sanitizer

@jonkeane
Copy link
Member

I've triggered the sanitizer jobs.

IIUC, I think you can trigger them on your own with a comment like the one I sent @zanmato1984 I don't believe there are restrictions on who is allowed to send that comment (and our CI here looks for the comment and then does the rest)

Copy link

Revision: a8d8b67

Submitted crossbow builds: ursacomputing/crossbow @ actions-c36b6c7141

Task Status
test-fedora-r-clang-sanitizer GitHub Actions
test-ubuntu-r-sanitizer GitHub Actions

@zanmato1984
Copy link
Collaborator Author

I've triggered the sanitizer jobs.

IIUC, I think you can trigger them on your own with a comment like the one I sent @zanmato1984 I don't believe there are restrictions on who is allowed to send that comment (and our CI here looks for the comment and then does the rest)

Wow, thank you for the tips. I'll try myself next time :)

@github-actions github-actions bot added awaiting merge Awaiting merge and removed awaiting change review Awaiting change review labels Apr 30, 2024
@bkietz bkietz merged commit 0ef7351 into apache:main Apr 30, 2024
36 of 38 checks passed
@bkietz bkietz removed the awaiting merge Awaiting merge label Apr 30, 2024
Copy link

After merging your PR, Conbench analyzed the 7 benchmarking runs that have been run so far on merge-commit 0ef7351.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details. It also includes information about 66 possible false positives for unstable benchmarks that are known to sometimes produce them.

tolleybot pushed a commit to tmct/arrow that referenced this pull request May 2, 2024
…er R 4.4 cleanups (apache#41403)

### Rationale for this change

Keep up with the state of the world, ensure we are maintaining backwards compatibility.

Resolves apache#41402

### What changes are included in this PR?

* Bump to 4.4 as the release
* Remove old 3.6 jobs now that we no longer support that; clean up code where we hardcode things fro 3.6 and below
* Move many of our CI jobs to [rhub's new containers](https://github.com/r-hub/containers). We were accidentally running stale R devel (from December 2023) because the other rhub images stopped being updated. (One exception to be done as a follow on: apache#41416)
* Resolve a number of extended test failures

With this PR R extended tests should be all green with the exceptions of:

* Two sanitizer jobs (test-fedora-r-clang-sanitizer, test-ubuntu-r-sanitizer) — which are being investigated / fixed in apache#41421
* Valgrind — I'm running one last run with a new suppression file. 
* Binary jobs — these work but fail at upload, see apache#41403 (comment)
* Windows R Release — failing on main, apache#41398

### Are these changes tested?

By definition.

### Are there any user-facing changes?

No.

* GitHub Issue: apache#41402

Lead-authored-by: Jonathan Keane <jkeane@gmail.com>
Co-authored-by: Jacob Wujciak-Jens <jacob@wujciak.de>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
tolleybot pushed a commit to tmct/arrow that referenced this pull request May 2, 2024
…to prevent ub (apache#41421)

### Rationale for this change

In apache#40237, I introduced scalar scratch space filling in concrete scalar sub-class constructor, in which there is a static down-casting of `this` to sub-class pointer. Though this is common in CRTP, it happens in base cast constructor. And this is reported in apache#41407 to be UB by UBSAN's "vptr" sanitizing.

I'm not a language lawyer to tell if this is a true/false-positive. So I proposed two approaches:
1. The easy way: add suppression in [1], like we already did for `shared_ptr`. But apparently this won't be feasible if this is a true-positive (need some language lawyer's help to confirm).
2. The hard way: totally avoid this so-to-speak UB but may introduce more boilerplate code. This PR is the hard way.

[1] https://github.com/apache/arrow/blob/main/r/tools/ubsan.supp

### What changes are included in this PR?

Make `FillScratchSpace` static.

### Are these changes tested?

The existing UT should cover it well.

### Are there any user-facing changes?

None.

* GitHub Issue: apache#41407

Lead-authored-by: Ruoxi Sun <zanmato1984@gmail.com>
Co-authored-by: Rossi Sun <zanmato1984@gmail.com>
Co-authored-by: Benjamin Kietzman <bengilgit@gmail.com>
Signed-off-by: Benjamin Kietzman <bengilgit@gmail.com>
raulcd pushed a commit that referenced this pull request May 3, 2024
…vent ub (#41421)

### Rationale for this change

In #40237, I introduced scalar scratch space filling in concrete scalar sub-class constructor, in which there is a static down-casting of `this` to sub-class pointer. Though this is common in CRTP, it happens in base cast constructor. And this is reported in #41407 to be UB by UBSAN's "vptr" sanitizing.

I'm not a language lawyer to tell if this is a true/false-positive. So I proposed two approaches:
1. The easy way: add suppression in [1], like we already did for `shared_ptr`. But apparently this won't be feasible if this is a true-positive (need some language lawyer's help to confirm).
2. The hard way: totally avoid this so-to-speak UB but may introduce more boilerplate code. This PR is the hard way.

[1] https://github.com/apache/arrow/blob/main/r/tools/ubsan.supp

### What changes are included in this PR?

Make `FillScratchSpace` static.

### Are these changes tested?

The existing UT should cover it well.

### Are there any user-facing changes?

None.

* GitHub Issue: #41407

Lead-authored-by: Ruoxi Sun <zanmato1984@gmail.com>
Co-authored-by: Rossi Sun <zanmato1984@gmail.com>
Co-authored-by: Benjamin Kietzman <bengilgit@gmail.com>
Signed-off-by: Benjamin Kietzman <bengilgit@gmail.com>
tolleybot pushed a commit to tmct/arrow that referenced this pull request May 4, 2024
…to prevent ub (apache#41421)

### Rationale for this change

In apache#40237, I introduced scalar scratch space filling in concrete scalar sub-class constructor, in which there is a static down-casting of `this` to sub-class pointer. Though this is common in CRTP, it happens in base cast constructor. And this is reported in apache#41407 to be UB by UBSAN's "vptr" sanitizing.

I'm not a language lawyer to tell if this is a true/false-positive. So I proposed two approaches:
1. The easy way: add suppression in [1], like we already did for `shared_ptr`. But apparently this won't be feasible if this is a true-positive (need some language lawyer's help to confirm).
2. The hard way: totally avoid this so-to-speak UB but may introduce more boilerplate code. This PR is the hard way.

[1] https://github.com/apache/arrow/blob/main/r/tools/ubsan.supp

### What changes are included in this PR?

Make `FillScratchSpace` static.

### Are these changes tested?

The existing UT should cover it well.

### Are there any user-facing changes?

None.

* GitHub Issue: apache#41407

Lead-authored-by: Ruoxi Sun <zanmato1984@gmail.com>
Co-authored-by: Rossi Sun <zanmato1984@gmail.com>
Co-authored-by: Benjamin Kietzman <bengilgit@gmail.com>
Signed-off-by: Benjamin Kietzman <bengilgit@gmail.com>
rok pushed a commit to tmct/arrow that referenced this pull request May 8, 2024
…to prevent ub (apache#41421)

### Rationale for this change

In apache#40237, I introduced scalar scratch space filling in concrete scalar sub-class constructor, in which there is a static down-casting of `this` to sub-class pointer. Though this is common in CRTP, it happens in base cast constructor. And this is reported in apache#41407 to be UB by UBSAN's "vptr" sanitizing.

I'm not a language lawyer to tell if this is a true/false-positive. So I proposed two approaches:
1. The easy way: add suppression in [1], like we already did for `shared_ptr`. But apparently this won't be feasible if this is a true-positive (need some language lawyer's help to confirm).
2. The hard way: totally avoid this so-to-speak UB but may introduce more boilerplate code. This PR is the hard way.

[1] https://github.com/apache/arrow/blob/main/r/tools/ubsan.supp

### What changes are included in this PR?

Make `FillScratchSpace` static.

### Are these changes tested?

The existing UT should cover it well.

### Are there any user-facing changes?

None.

* GitHub Issue: apache#41407

Lead-authored-by: Ruoxi Sun <zanmato1984@gmail.com>
Co-authored-by: Rossi Sun <zanmato1984@gmail.com>
Co-authored-by: Benjamin Kietzman <bengilgit@gmail.com>
Signed-off-by: Benjamin Kietzman <bengilgit@gmail.com>
rok pushed a commit to tmct/arrow that referenced this pull request May 8, 2024
…to prevent ub (apache#41421)

### Rationale for this change

In apache#40237, I introduced scalar scratch space filling in concrete scalar sub-class constructor, in which there is a static down-casting of `this` to sub-class pointer. Though this is common in CRTP, it happens in base cast constructor. And this is reported in apache#41407 to be UB by UBSAN's "vptr" sanitizing.

I'm not a language lawyer to tell if this is a true/false-positive. So I proposed two approaches:
1. The easy way: add suppression in [1], like we already did for `shared_ptr`. But apparently this won't be feasible if this is a true-positive (need some language lawyer's help to confirm).
2. The hard way: totally avoid this so-to-speak UB but may introduce more boilerplate code. This PR is the hard way.

[1] https://github.com/apache/arrow/blob/main/r/tools/ubsan.supp

### What changes are included in this PR?

Make `FillScratchSpace` static.

### Are these changes tested?

The existing UT should cover it well.

### Are there any user-facing changes?

None.

* GitHub Issue: apache#41407

Lead-authored-by: Ruoxi Sun <zanmato1984@gmail.com>
Co-authored-by: Rossi Sun <zanmato1984@gmail.com>
Co-authored-by: Benjamin Kietzman <bengilgit@gmail.com>
Signed-off-by: Benjamin Kietzman <bengilgit@gmail.com>
vibhatha pushed a commit to vibhatha/arrow that referenced this pull request May 25, 2024
…er R 4.4 cleanups (apache#41403)

### Rationale for this change

Keep up with the state of the world, ensure we are maintaining backwards compatibility.

Resolves apache#41402

### What changes are included in this PR?

* Bump to 4.4 as the release
* Remove old 3.6 jobs now that we no longer support that; clean up code where we hardcode things fro 3.6 and below
* Move many of our CI jobs to [rhub's new containers](https://github.com/r-hub/containers). We were accidentally running stale R devel (from December 2023) because the other rhub images stopped being updated. (One exception to be done as a follow on: apache#41416)
* Resolve a number of extended test failures

With this PR R extended tests should be all green with the exceptions of:

* Two sanitizer jobs (test-fedora-r-clang-sanitizer, test-ubuntu-r-sanitizer) — which are being investigated / fixed in apache#41421
* Valgrind — I'm running one last run with a new suppression file. 
* Binary jobs — these work but fail at upload, see apache#41403 (comment)
* Windows R Release — failing on main, apache#41398

### Are these changes tested?

By definition.

### Are there any user-facing changes?

No.

* GitHub Issue: apache#41402

Lead-authored-by: Jonathan Keane <jkeane@gmail.com>
Co-authored-by: Jacob Wujciak-Jens <jacob@wujciak.de>
Signed-off-by: Jonathan Keane <jkeane@gmail.com>
vibhatha pushed a commit to vibhatha/arrow that referenced this pull request May 25, 2024
…to prevent ub (apache#41421)

### Rationale for this change

In apache#40237, I introduced scalar scratch space filling in concrete scalar sub-class constructor, in which there is a static down-casting of `this` to sub-class pointer. Though this is common in CRTP, it happens in base cast constructor. And this is reported in apache#41407 to be UB by UBSAN's "vptr" sanitizing.

I'm not a language lawyer to tell if this is a true/false-positive. So I proposed two approaches:
1. The easy way: add suppression in [1], like we already did for `shared_ptr`. But apparently this won't be feasible if this is a true-positive (need some language lawyer's help to confirm).
2. The hard way: totally avoid this so-to-speak UB but may introduce more boilerplate code. This PR is the hard way.

[1] https://github.com/apache/arrow/blob/main/r/tools/ubsan.supp

### What changes are included in this PR?

Make `FillScratchSpace` static.

### Are these changes tested?

The existing UT should cover it well.

### Are there any user-facing changes?

None.

* GitHub Issue: apache#41407

Lead-authored-by: Ruoxi Sun <zanmato1984@gmail.com>
Co-authored-by: Rossi Sun <zanmato1984@gmail.com>
Co-authored-by: Benjamin Kietzman <bengilgit@gmail.com>
Signed-off-by: Benjamin Kietzman <bengilgit@gmail.com>
jonkeane added a commit to jonkeane/arrow that referenced this pull request Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants