apply: Fix a patch corruption related to EOFNL handling#5209
Merged
ethomson merged 2 commits intolibgit2:masterfrom Sep 9, 2019
Merged
apply: Fix a patch corruption related to EOFNL handling#5209ethomson merged 2 commits intolibgit2:masterfrom
ethomson merged 2 commits intolibgit2:masterfrom
Conversation
Use of apply's API can lead to an improper patch application and a corruption of the modified file. The issue is caused by mishandling of the end of file changes if there are several hunks to apply. The new line character is added to a line from a wrong hunk. The solution is to modify apply_hunk() to add the newline character at the end of a line from a right hunk.
Member
|
Thanks a lot for your fix! Could you please provide test data that has resulted in corruption previous to this change? Additional kudos if it comes as a unit test to verify that this actually fixes the issue and that we won't regress in the future. It's perfectly fine though if you provide the reproduction steps, only, then I'd help you out and implement a unit test for you :) |
Introduce an unit test to validate that git_apply__patch() properly handles EOFNL changes in case of patches with several hunks.
Contributor
Author
|
Hi Patrick, could you please check the unit test? Thank you. |
ethomson
approved these changes
Sep 9, 2019
Member
|
Thanks @mkostyuk! |
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.
Use of apply's API can lead to an improper patch application and a corruption
of the modified file.
The issue is caused by mishandling of the end of file changes if there are
several hunks to apply. The new line character is added to a line from a wrong
hunk.
The solution is to modify apply_hunk() to add the newline character at the end
of a line from a right hunk.