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:ccd59eeb-eccc-f6ff-9036-2c6335ad034f |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8708:2BBCDD:FD39C0:1539AC0:6969920E |
| html-safe-nonce | 3f5eb4cc1bfd25ec7ad8dd2c4aa5b798d21cf2e82e79ae9d474ec33ea80f558c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NzA4OjJCQkNERDpGRDM5QzA6MTUzOUFDMDo2OTY5OTIwRSIsInZpc2l0b3JfaWQiOiIyNTc3NjUzNTMzODg3Nzk1NzI2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 65dd61e811c812387954d58114d19d17a52df0917bc4e0dfbbc42621fd7c2116 |
| 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 | 3542e147982176a7ebaa23dfb559c8af16f721c03ec560c68c56b64a0f35e751 |
| 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 | af80af7cc9e3de9c336f18b208a600950a3c187c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width