FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Avoid `memcpy()`-ing 0-length vectors by aitap · Pull Request #6820 · Rdatatable/data.table · GitHub

Avoid memcpy()-ing 0-length vectors - #6820

Merged
aitap merged 3 commits into
masterfrom
fix-0len
Feb 23, 2025
Merged

aitap merged 3 commits into
masterfrom
fix-0len

Conversation

aitap commented Feb 17, 2025

Copy link
Copy Markdown
Member

The C standard (before C23) says that giving invalid pointers, even with length=0, to memcpy() is undefined behaviour. R returns an invalid pointer for vectors of length 0, so avoid calls to memcpy() altogether in such cases.

Fixes: #6819

The C standard (before C23) says that giving invalid pointers, even with
length=0, to memcpy() is undefined behaviour. R returns an invalid
pointer for vectors of length 0, so avoid calls to memcpy() altogether
in such cases.

codecov Bot commented Feb 17, 2025
edited
Loading

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.64%. Comparing base (f231b5d) to head (4773ceb).
Report is 11 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6820   +/-   ##
=======================================
  Coverage   98.64%   98.64%           
=======================================
  Files          79       79           
  Lines       14642    14650    +8     
=======================================
+ Hits        14444    14452    +8     
  Misses        198      198           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

github-actions Bot commented Feb 17, 2025
edited
Loading

Copy link
Copy Markdown

Generated via commit 4773ceb

Download link for the artifact containing the test results: ↓ atime-results.zip

Task Duration
R setup and installing dependencies 4 minutes and 32 seconds
Installing different package versions 8 minutes and 30 seconds
Running and plotting the test cases 2 minutes and 35 seconds

Comment thread src/dogroups.c Outdated

MichaelChirico left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM, feel free to merge whether or not you want to make my suggested change.

Do we have any way of preventing this from recurring in the future?

aitap and others added 2 commits February 23, 2025 14:11
Co-authored-by: Michael Chirico <chiricom@google.com>
Co-authored-by: Michael Chirico <chiricom@google.com>

aitap commented Feb 23, 2025

Copy link
Copy Markdown
Member Author

Maybe not literally preventing, but a sanitizer-enabled CI check should be able to catch similar problems as soon as they land on master.

Then why does rocker/r-devel-san-clang built using the same Debian Testing clang miss this, while our own container doesn't? Not sure. Maybe due to -O3 optimizing some of it away?

aitap merged commit 299d44d into master Feb 23, 2025
aitap deleted the fix-0len branch February 23, 2025 14:38
aitap added a commit that referenced this pull request May 21, 2025
* Avoid memcpy()-ing 0-length vectors

The C standard (before C23) says that giving invalid pointers, even with
length=0, to memcpy() is undefined behaviour. R returns an invalid
pointer for vectors of length 0, so avoid calls to memcpy() altogether
in such cases.

* Use early returns for 0-length cases

Co-authored-by: Michael Chirico <chiricom@google.com>
TysonStanley pushed a commit that referenced this pull request May 25, 2025
* Avoid memcpy()-ing 0-length vectors

The C standard (before C23) says that giving invalid pointers, even with
length=0, to memcpy() is undefined behaviour. R returns an invalid
pointer for vectors of length 0, so avoid calls to memcpy() altogether
in such cases.

* Use early returns for 0-length cases

Co-authored-by: Michael Chirico <chiricom@google.com>
MichaelChirico added a commit that referenced this pull request May 26, 2025
* Avoid `memcpy()`-ing 0-length vectors (#6820)

* Avoid memcpy()-ing 0-length vectors

The C standard (before C23) says that giving invalid pointers, even with
length=0, to memcpy() is undefined behaviour. R returns an invalid
pointer for vectors of length 0, so avoid calls to memcpy() altogether
in such cases.

* Use early returns for 0-length cases

Co-authored-by: Michael Chirico <chiricom@google.com>

* Avoid memcpy() of empty vector (#6911)

* Avoid memcpy() of empty vector

* in getidcols() too

* Add a test case

Distilled from the `melt()` call here:

https://github.com/gdemin/expss/blob/d498caf72a9938ac71b9e06fd61485cd0347d607/tests/testthat/test_subtotal.R#L161-L166

* NEWS entry

---------

Co-authored-by: Michael Chirico <chiricom@google.com>
Co-authored-by: Michael Chirico <michaelchirico4@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

growVector, copyAsPlain may formally cause undefined behaviour with 0-length vectors

2 participants


Back | FazBrowse Home | New Git URL