Avoid null ptr dereferences for BlameHunk missing Signatures#1254
Merged
Conversation
When a `BlameHunk` is created from an arbitrary buffer via `Blame::blame_buffer()`, the original and final committer and author can be missing. This leads to creating `Signature` objects holding null pointers; subsequent attempts to access the name or email of the signature leads to null pointer dereferences. The new tests are currently failing and exists to show the error - they could not be split up and 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 null pointer is dereferenced, and the attribute only works with unwinding panics, I'm not sure. The test also confirms that the non-signature methods still work with arbitrary hunks.
The `BlameHunk` might have null pointers for the original and final committer and author. The following methods now return an `Option<Signature<'_>>` rather than a `Signature<'_>` * `BlameHunk::final_signature()` * `BlameHunk::final_committer()` * `BlameHunk::orig_signature()` * `BlameHunk::orig_committer()` Fixes rust-lang#1253
weihanglo
approved these changes
May 15, 2026
This was referenced May 16, 2026
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1253