[Python-modules-team] Bug#857171: import of git can cause import failures of unrelated modules due to undefined variable
Yaroslav Halchenko
debian at onerussian.com
Wed Mar 8 14:48:09 UTC 2017
Package: python-git
Version: 2.1.0-1
Severity: critical
Tags: upstream patch
$> docker run -it --rm debian:stretch
root at 7f7cfee9f6fa:/# apt-get update -qqq; apt-get install -qqq -y python-h5py python-git
debconf: delaying package configuration, since apt-utils is not installed
(Reading database ... 6415 files and directories currently installed.)
Preparing to unpack .../perl-base_5.24.1-1_amd64.deb ...
...
done.
root at 7f7cfee9f6fa:/# python -c 'import git; import h5py'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/h5py/__init__.py", line 60, in <module>
from .tests import run_tests
File "/usr/lib/python2.7/dist-packages/h5py/tests/__init__.py", line 15, in <module>
from . import old, hl
File "/usr/lib/python2.7/dist-packages/h5py/tests/old/__init__.py", line 4, in <module>
from . import ( test_attrs,
File "/usr/lib/python2.7/dist-packages/h5py/tests/old/test_group.py", line 41, in <module>
fsencode(u"α")
File "/usr/lib/python2.7/dist-packages/h5py/_hl/compat.py", line 68, in fsencode
return filename.encode(encoding, errors)
File "/usr/lib/python2.7/dist-packages/git/compat.py", line 180, in surrogateescape_handler
decoded = replace_surrogate_encode(mystring)
File "/usr/lib/python2.7/dist-packages/git/compat.py", line 207, in replace_surrogate_encode
raise exc
NameError: global name 'exc' is not defined
Issue was reported and fixed upstream through a sequence of two PRs (heh) which
are compressed into a single small patch attached to this report. This issue
already gave me notable pain, so quick update in stretch would be
appreciated!
here is a proof of it working:
root at 7f7cfee9f6fa:/usr/lib/python2.7/dist-packages# curl http://www.onerussian.com/tmp/exc_exception.patch | patch -p1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 1338 100 1338 0 0 210k 0 --:--:-- --:--:-- --:--:-- 217k
patching file git/compat.py
root at 7f7cfee9f6fa:/usr/lib/python2.7/dist-packages# cd /tmp
root at 7f7cfee9f6fa:/tmp# python -c 'import git; import h5py'
root at 7f7cfee9f6fa:/tmp#
-- System Information:
Debian Release: 9.0
APT prefers testing
APT policy: (900, 'testing'), (600, 'unstable'), (300, 'experimental'), (100, 'unstable-debug')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 4.9.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
Versions of packages python-git depends on:
ii git [git-core] 1:2.11.0-2
ii git-core 1:2.11.0-2
ii python-gitdb 2.0.0-2
pn python:any <none>
python-git recommends no packages.
Versions of packages python-git suggests:
ii python-git-doc 2.1.0-1
ii python-smmap 2.0.1-1
-- debconf-show failed
-------------- next part --------------
From: Yaroslav Halchenko <debian at onerussian.com>
Subject: Pass exc value to be re-raised
Origin: https://github.com/gitpython-developers/GitPython/pull/598
https://github.com/gitpython-developers/GitPython/pull/603
Bug-Debian: http://bugs.debian.org/
Bug-Ubuntu: https://launchpad.net/bugs/
Applied-Upstream: https://github.com/gitpython-developers/GitPython/commit/9ce2a4b235d2ebc38c3e081c1036e39bde9be036
Last-Update: 2017-03-08
diff --git a/git/compat.py b/git/compat.py
index a2403d6..b804585 100644
--- a/git/compat.py
+++ b/git/compat.py
@@ -177,7 +177,7 @@ def surrogateescape_handler(exc):
# exception anyway after this function is called, even though I think
# it's doing what it should. It seems that the strict encoder is called
# to encode the unicode string that this function returns ...
- decoded = replace_surrogate_encode(mystring)
+ decoded = replace_surrogate_encode(mystring, exc)
else:
raise exc
except NotASurrogateError:
@@ -189,7 +189,7 @@ class NotASurrogateError(Exception):
pass
-def replace_surrogate_encode(mystring):
+def replace_surrogate_encode(mystring, exc):
"""
Returns a (unicode) string, not the more logical bytes, because the codecs
register_error functionality expects this.
More information about the Python-modules-team
mailing list