Title: Fix UnicodeDecodeError when reading packed-refs with non-UTF8 characters by MirrorDNA-Reflection-Protocol · Pull Request #2091 · gitpython-developers/GitPython · GitHub
Open Graph Title: Fix UnicodeDecodeError when reading packed-refs with non-UTF8 characters by MirrorDNA-Reflection-Protocol · Pull Request #2091 · gitpython-developers/GitPython
X Title: Fix UnicodeDecodeError when reading packed-refs with non-UTF8 characters by MirrorDNA-Reflection-Protocol · Pull Request #2091 · gitpython-developers/GitPython
Description: Summary Fixes #2064 The packed-refs file can contain ref names that are not valid UTF-8 (e.g., Latin-1 encoded tag names created by older Git versions or systems with different locale settings). Previously, GitPython would fail with UnicodeDecodeError when reading such files. Reproduction As described in #2064: git clone https://github.com/ACRA/acra cd acra python -c 'import git; print(git.Repo(".").tags)' Before fix: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 6216: invalid continuation byte After fix: Successfully reads all 101 tags. Changes Add errors='surrogateescape' to the open() call in _iter_packed_refs() This allows reading files with arbitrary byte sequences while preserving valid UTF-8 as text Add test that verifies non-UTF8 packed-refs can be read successfully Technical Details The surrogateescape error handler is Python's standard approach for handling potentially non-UTF8 data in filesystem operations. It: Passes through valid UTF-8 unchanged Converts invalid byte sequences to Unicode surrogate characters (\uDC80-\uDCFF) Preserves the original bytes in a reversible way (can be re-encoded back to original bytes) This is the same approach used by Python's os.fsdecode() and is recommended for filesystem operations where encoding may be unknown or mixed.
Open Graph Description: Summary Fixes #2064 The packed-refs file can contain ref names that are not valid UTF-8 (e.g., Latin-1 encoded tag names created by older Git versions or systems with different locale settings). Pr...
X Description: Summary Fixes #2064 The packed-refs file can contain ref names that are not valid UTF-8 (e.g., Latin-1 encoded tag names created by older Git versions or systems with different locale settings). Pr...
Opengraph URL: https://github.com/gitpython-developers/GitPython/pull/2091
X: @github
Domain: togithub.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:6858577f-52f4-1b56-6df7-5b96bab1b2d5 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B5EE:25B5C6:12A8B8:19EAA9:696A1930 |
| html-safe-nonce | 4d1a85d7e961089578e35aec5ebe39378b6908bb9d3ee536b25a3c8383be85aa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNUVFOjI1QjVDNjoxMkE4Qjg6MTlFQUE5OjY5NkExOTMwIiwidmlzaXRvcl9pZCI6IjE0MTY0ODk1NTc1NDMyMjk3NDQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d12022881f7846be36798f2b8aacbf0d71b80c960c2a4b6a69e2c687d34616e3 |
| hovercard-subject-tag | pull_request:3079227966 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/gitpython-developers/GitPython/pull/2091/files |
| twitter:image | https://avatars.githubusercontent.com/u/239564541?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/239564541?s=400&v=4 |
| og:image:alt | Summary Fixes #2064 The packed-refs file can contain ref names that are not valid UTF-8 (e.g., Latin-1 encoded tag names created by older Git versions or systems with different locale settings). Pr... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 34a52bd10bd674f68e5c1b6b74413b79bf2ca20c551055ace3f7cdd112803923 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/gitpython-developers/GitPython git https://github.com/gitpython-developers/GitPython.git |
| octolytics-dimension-user_id | 503709 |
| octolytics-dimension-user_login | gitpython-developers |
| octolytics-dimension-repository_id | 1126087 |
| octolytics-dimension-repository_nwo | gitpython-developers/GitPython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1126087 |
| octolytics-dimension-repository_network_root_nwo | gitpython-developers/GitPython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e8bd37502700f365b18a4d39acf7cb7947e11b1a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width