Skip to content

Fixed missing null terminator in config string used in Booster::save_buffer. - #13

Open
metasim wants to merge 1 commit into
marcomq:masterfrom
datashapesai:fix/missing-null-terminator
Open

Fixed missing null terminator in config string used in Booster::save_buffer.#13
metasim wants to merge 1 commit into
marcomq:masterfrom
datashapesai:fix/missing-null-terminator

Conversation

@metasim

@metasim metasim commented Jun 22, 2026

Copy link
Copy Markdown

Use of an address sanitizer on Windows 11 detected a missing null terminator required when passing strings across the FFI boundary.

This fix wraps the config string in a Cstring, which ensures a null terminator.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a critical issue in model buffer saving that improves memory safety and reliability. Proper string handling ensures configurations are correctly processed during model serialization, preventing potential crashes or data corruption.

@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 26661e56-9621-4284-a529-7f138cabe7b1

📥 Commits

Reviewing files that changed from the base of the PR and between 2a357c2 and 56fe82a.

📒 Files selected for processing (1)
  • src/booster.rs

📝 Walkthrough

Walkthrough

In Booster::save_buffer, the JSON config string passed to the XGBoost FFI function XGBoosterSaveModelToBuffer is now wrapped in ffi::CString::new(...) to ensure NUL-termination, replacing the previous use of .as_bytes().as_ptr() on a non-NUL-terminated Rust String. CString construction errors are mapped to XGBError.

Changes

FFI Config String Fix

Layer / File(s) Summary
NUL-terminated CString in save_buffer
src/booster.rs
save_buffer now constructs a ffi::CString from the formatted JSON config string and passes config.as_ptr() to XGBoosterSaveModelToBuffer, replacing the previous config.as_bytes().as_ptr() call that lacked a NUL terminator. CString creation failure is explicitly handled via XGBError.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

A rabbit once hopped through the FFI gate,
But the string it passed in had no null — oh fate!
Now wrapped in a CString, all tidy and right,
The pointer is safe as it marches to fight.
🐇 NUL-terminated, at last! What delight!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title directly and accurately describes the primary change: fixing a missing null terminator in a config string in the Booster::save_buffer method, which aligns perfectly with the changeset and PR objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant