Repository navigation
fix(tag): split tag object headers at line feeds only - #2290
Open
Keerthana-64 wants to merge 1 commit into
Open
Keerthana-64 wants to merge 1 commit into
Keerthana-64 wants to merge 1 commit into
Conversation
`TagObject._set_cache_` split the decoded tag object with `str.splitlines()` and then read the headers by position, taking `lines[3]` as the tagger. `str.splitlines()` also breaks at `\r`, `\v`, `\f`, `\x1c`-`\x1e`, `\x85`, U+2028 and U+2029, but git ends a header only at a line feed. A U+2028 inside the `tag` header of an untrusted tag object therefore shifts every later header by one line in GitPython only. With `tag v1<U+2028>tagger Linus Torvalds <torvalds@linux-foundation.org> 1700000000 +0000` followed by a real `tagger Mallory <m@evil.example> ...` line, `git cat-file tag`, `git show` and `git for-each-ref --format=%(taggername)` report Mallory, while GitPython reported `tag == "v1"` and Linus Torvalds as the tagger. The object passes `git fsck --strict` and a clone with `transfer.fsckObjects=true`, because git only warns `badTagName`. The fix splits at `"\n"` and drops the trailing empty element, so tags that only use line feeds parse exactly as before. A `\r` or U+2028 inside the message is now kept, as git shows it. The new test in `test/test_refs.py` fails before the change and passes after it. `ruff`, `ruff format --check` and `mypy` are clean. On my machine the full suite has 3 failures (`test_empty_repo`, `test_rebasing`, `test_diff_with_staged_file`), and all 3 also fail without this change.
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.
TagObject._set_cache_split the decoded tag object withstr.splitlines()and then read the headers by position, takinglines[3]as the tagger.str.splitlines()also breaks at\r,\v,\f,\x1c-\x1e,\x85, U+2028 and U+2029, but git ends a header only at a line feed. A U+2028 inside thetagheader of an untrusted tag object therefore shifts every later header by one line in GitPython only. Withtag v1<U+2028>tagger Linus Torvalds <torvalds@linux-foundation.org> 1700000000 +0000followed by a realtagger Mallory <m@evil.example> ...line,git cat-file tag,git showandgit for-each-ref --format=%(taggername)report Mallory, while GitPython reportedtag == "v1"and Linus Torvalds as the tagger. The object passesgit fsck --strictand a clone withtransfer.fsckObjects=true, because git only warnsbadTagName.The fix splits at
"\n"and drops the trailing empty element, so tags that only use line feeds parse exactly as before. A\ror U+2028 inside the message is now kept, as git shows it. The new test intest/test_refs.pyfails before the change and passes after it.ruff,ruff format --checkandmypyare clean. On my machine the full suite has 3 failures (test_empty_repo,test_rebasing,test_diff_with_staged_file), and all 3 also fail without this change.