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

R memory safety issues #7246

Closed
david-cortes opened this issue Sep 18, 2021 · 0 comments · Fixed by #9823
Closed

R memory safety issues #7246

david-cortes opened this issue Sep 18, 2021 · 0 comments · Fixed by #9823

Comments

@david-cortes
Copy link
Contributor

From a similar issue in lightgbm: microsoft/LightGBM#4597

The R interface for XGBoost throws R errors from C++ exception objects' char pointers:

error(e.what()); \

R errors trigger a C long jump, and if done from a catch clause, will leak the C++ exception object under GCC and CLANG.

Additionally, some functions will call R's asChar and retrieve a pointer from it through CHAR:

CHECK_CALL(XGBoosterSetParam(R_ExternalPtrAddr(handle),

I'm not 100% sure about it (asChar is a bit different from other functions), but I think that:

  • The result of that asChar needs to be PROTECTed just like other R objects, otherwise it can lead to use-after-free errors if it does any coercion from the original object.
  • Calling asChar can also produce a long jump if it ends up allocating a new object as it coerces the input, and if that allocation fails, would lead to leaking C++ objects (e.g.
    vec_names.push_back(std::string(CHAR(asChar(VECTOR_ELT(evnames, i)))));
    ).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 2.0 Done
Development

Successfully merging a pull request may close this issue.

2 participants