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: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:c58b94db-93d4-ea7f-ca77-8747d6ebd6b3 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | CE08:36C7A:13B9A7:1AE99B:69696535 |
| html-safe-nonce | 2136f3f5e56d7f66b4cd8548226ec84e8f6b0126eb07d48f1a8cc8142c4b9233 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRTA4OjM2QzdBOjEzQjlBNzoxQUU5OUI6Njk2OTY1MzUiLCJ2aXNpdG9yX2lkIjoiNzMzMTM5ODU0NjI3MjkwNDUwMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f5482c7afc5b8c7da6959517741c793759d4594c1f215716fbba93bdb6154cab |
| 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 | c6f193beb8ff08443adc07685d75302ab8aaf0a135f6e251c3ff3112c8deb881 |
| 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 | ec4d88fbe7ed62446d90b0a6d8e6db4248a8f8b8 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width