Skip to content

Fix unsoundness in git2::MergeFileResult::content() for empty content#1282

Merged
ehuss merged 2 commits into
rust-lang:mainfrom
DanielEScherzer:empty-merge-content
Jun 20, 2026
Merged

Fix unsoundness in git2::MergeFileResult::content() for empty content#1282
ehuss merged 2 commits into
rust-lang:mainfrom
DanielEScherzer:empty-merge-content

Conversation

@DanielEScherzer

Copy link
Copy Markdown
Contributor

Fixes #1281

@rustbot rustbot added the S-waiting-on-review Status: Waiting on review label Jun 19, 2026
When a `MergeFileResult` is created with no actual file content (e.g. via
`git2::merge_file()`), the content is empty and the pointer to it is NULL; this
violates the preconditions of `slice::from_raw_parts()`, which requires that
the provided pointer be non-null.

The new test is currently failing and exists to show the error - it could not
be marked with `#[should_panic]`, which does not appear to work here. This may
be because the error message is that "thread caused non-unwinding panic.
aborting." after the problematic `slice::from_raw_parts()` call, and the
attribute only works with unwinding panics, I'm not sure.

There is already an existing test for confirming that
`MergeFileResult::content()` works properly with non-empty content.
When there is no data, rather than using `slice::from_raw_parts()` with a null
pointer (which is unsound), just return an empty slice directly.

Fixes rust-lang#1281

@ehuss ehuss left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ehuss ehuss added this pull request to the merge queue Jun 20, 2026
Merged via the queue into rust-lang:main with commit ec20d50 Jun 20, 2026
8 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Waiting on review label Jun 20, 2026
@DanielEScherzer DanielEScherzer deleted the empty-merge-content branch June 21, 2026 02:05
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.

Unsound slice::from_raw_parts() in git2::MergeFileResult::content()

3 participants