Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of paths with white spaces on diff parsing #6654

Closed
wants to merge 1 commit into from

Conversation

Nfsaavedra
Copy link

Context

While I was using pygit2 I got a segmentation fault when trying to use pygit2.Repository.apply with a diff obtained by using parse_diff. The diff contained a removal of a file with spaces on its path and the path was not quoted:

diff --git a/.run/Run IDE with Plugin.run.xml b/.run/Run IDE with Plugin.run.xml

What I found was that when I transformed the diff obtained from parse_diff back to a string, the previous line was changed to:

diff --git a/.run/Run IDE with Plugin.run.xml /dev/null

For some reason that I still don't fully understand, but that makes some sense to me, the /dev/null created a segmentation fault on the apply. I looked into pygit2 and found out that the problem probably was on libgit2.

Changes

I was able to debug and find out that the function header_path_len was the culprit. Since previously this function stopped on a white space if the path is not quoted, then the header I gave as example would be incorrectly parsed. Given this, I changed the function so it only stops when it reaches b/ or "b/. This still has a problem if a folder called b (white space followed by b) or "b is used but it seems pretty unlikely.

Tests

I created a test for delete mode since a test for create mode already existed. However I found it weird that the tests expected that on create mode the result for the old file path was NULL. The reason I found it weird is that for "normal" paths, i.e. paths without spaces, the result was the path of the file instead of NULL. For this reason, I also changed the test for create mode to go accordingly with the behavior of "normal" paths.

@Nfsaavedra Nfsaavedra changed the title Fix handling of white spaces on diff parsing Fix handling of paths with white spaces on diff parsing Nov 9, 2023
@arroz
Copy link
Contributor

arroz commented Nov 9, 2023

We have a patch waiting for what I think is the same problem: #6295 I had missed the review there, just committed the suggested code.

@Nfsaavedra
Copy link
Author

Nfsaavedra commented Nov 9, 2023

We have a patch waiting for what I think is the same problem: #6295 I had missed the review there, just committed the suggested code.

Oops forgot to check that, thanks! I'll close this PR

@Nfsaavedra Nfsaavedra closed this Nov 9, 2023
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.

None yet

2 participants