Fix crash when staging lines with the index locked#2771
Merged
lucasderraugh merged 1 commit intogit-up:masterfrom Apr 23, 2026
Merged
Fix crash when staging lines with the index locked#2771lucasderraugh merged 1 commit intogit-up:masterfrom
lucasderraugh merged 1 commit intogit-up:masterfrom
Conversation
These error overrides might have worked at some point? But in my quick tests, now, if the function errors, it'll return a null diff. As a result of the override, the null diff unexpectedly goes in the rest of GUK. IIRC, a GCDiff gets created with it, GCDiff._cacheDeltasIfNeeded tries to allocate an array of capacity -1 (which maps to unsigned int 18446744073709551615) because that's the output of git_diff_num_deltas on a null value, and that crashes.
Collaborator
|
@Cykelero What happens when this path is hit and GIT_ELOCKED is returned? Do we throw some kind of error UI? |
Contributor
Author
Collaborator
|
Thanks! |
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 #2768.
Why it crashes
See the linked issue for a LLM-generated attempt at diagnosing the issue; it seems rather correct. (the proposed solutions are pretty terrible though)
In a nutshell: in two spots*, GUK calls
git_diff_index_to_workdir(), and explicitly ignores its returned error if it’sGIT_ELOCKED. The reasoning is that we don’t care about failing to write the index: that’s just an optional, beneficial side-effect to our actual need, which is to get a diff.However, when failing in that way,
git_diff_index_to_workdir()does not return a diff**, it returns null! And so that null value is returned, silently makes its way through GUK, until this causes an array to be allocated with an incorrect size.*
diffWorkingDirectoryWithCommitanddiffWorkingDirectoryWithIndex, onGCRepository.** Presumably it did at some point, explaining why the code is written that way.
Reproducing
To reproduce, I had to patch
git_diff_index_to_workdir()to always write the index:Then, you can trigger the crash by staging an individual line. (that’s what I did in Retcon, anyway, but it should work in GitUp as well)
The fix
I removed the override altogether. When I tested, if
git_diff_index_to_workdir()returnsGIT_ELOCKED, it always returns an empty diff. Maybe that’s not always the case, but it doesn’t feel like we should trust its return value in these cases anyway.