diff --git a/debian/changelog b/debian/changelog
index 3514cc5ceab4d06200db09765d32582846795f14..c605afad87a0ac28f3ea5b09fbd7e269cebbe847 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+python-defaults (2.6.6-9) experimental; urgency=low
+
+  * dh_python2: fix a crash in packages with private extension (closes: 607555)
+    - test3 added (to test architecture dependent packages)
+
+ -- Piotr Ożarowski <piotr@debian.org>  Sun, 19 Dec 2010 20:27:23 +0100
+
 python-defaults (2.6.6-8) experimental; urgency=low
 
   * Fix typo in minimum required python version for packages generated with
diff --git a/dh_python2 b/dh_python2
index 1404f52cfc8defa7aad44a83bb665c646c1b74a7..8bbee3a8cdc181d00eef73f3d19bdb2f93a43cae 100755
--- a/dh_python2
+++ b/dh_python2
@@ -252,6 +252,9 @@ def share_2x(dir1, dir2, dc=None):
         common_files = cmpfiles(dir1, dir2, common_files, shallow=False)[0]
 
     for fn in common_files:
+        if fn.endswith('.so'):
+            # in unlikely case where extensions are exactly the same
+            continue
         fpath1 = join(dir1, fn)
         fpath2 = join(dir2, fn)
         fpath3 = join(dstdir, fn)
@@ -323,6 +326,8 @@ def scan(package, dname=None):
             if root.endswith('-packages'):
                 r['public_vers'].add(version)
         else:
+            # TODO: find a way to specify Python version private
+            # extension was build for
             version = False
             for i in private_to_check:
                 if root.startswith(join('debian', package, i)):
@@ -373,7 +378,7 @@ def scan(package, dname=None):
                 if fext == 'so':
                     (r if public_dir else
                      r['private_dirs'].setdefault(private_dir, {}))\
-                    ['public_ext'].add(version)
+                    .setdefault('public_ext', set()).add(version)
                     continue
                 elif fext == 'py':
                     (r if public_dir else
@@ -553,7 +558,8 @@ def main():
             if ext_for is None:  # no extension
                 if options.vrange and options.vrange != (None, None):
                     args += " -V %s" % vrange_str(options.vrange)
-            elif ext_for is False:  # extension's version not detected
+            elif False in ext_for:
+                # at least one extension's version not detected
                 if options.vrange and '-' not in vrange_str(options.vrange):
                     ver = vrange_str(options.vrange)
                 else:  # try shebang or default Python version
diff --git a/tests/Makefile b/tests/Makefile
index 61610d22a3d6d07a880fed8deb6fba786e27cc37..a6fe41faee9af511e792b5785db276ddcc4fbc92 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,7 +1,7 @@
 #!/usr/bin/make -f
 
 # enable or disable tests here:
-TESTS := test1 test2
+TESTS := test1 test2 test3
 
 all: $(TESTS)
 
diff --git a/tests/t3/Makefile b/tests/t3/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..891a239cfcd1472fd0f4fea4ae4e4099415ad666
--- /dev/null
+++ b/tests/t3/Makefile
@@ -0,0 +1,18 @@
+#!/usr/bin/make -f
+
+all: run check
+
+DPY=$(shell pyversions -d)
+
+run: clean
+	dpkg-buildpackage -b -us -uc
+
+check:
+	grep -q "pycompile -p python-foo /usr/lib/python-foo -V $(shell pyversions -vd)"\
+		debian/python-foo/DEBIAN/postinst
+	test -f debian/python-foo/usr/lib/${DPY}/dist-packages/foo/bar.so
+	test ! -f debian/python-foo/usr/share/pyshared/foo/bar.so
+
+clean:
+	./debian/rules clean
+	rm -rf lib/Foo.egg-info build
diff --git a/tests/t3/debian/changelog b/tests/t3/debian/changelog
new file mode 100644
index 0000000000000000000000000000000000000000..d91e7a7d7ef8b1397b343936897fc3d25c5b5ceb
--- /dev/null
+++ b/tests/t3/debian/changelog
@@ -0,0 +1,5 @@
+foo (0.1.1) unstable; urgency=low
+
+  * Initial release
+
+ -- Piotr Ożarowski <piotr@debian.org>  Sun, 19 Dec 2010 19:40:33 +0100
diff --git a/tests/t3/debian/compat b/tests/t3/debian/compat
new file mode 100644
index 0000000000000000000000000000000000000000..7f8f011eb73d6043d2e6db9d2c101195ae2801f2
--- /dev/null
+++ b/tests/t3/debian/compat
@@ -0,0 +1 @@
+7
diff --git a/tests/t3/debian/control b/tests/t3/debian/control
new file mode 100644
index 0000000000000000000000000000000000000000..c4e1f5f9836bafa82cff2fe0ac33bb1078f49431
--- /dev/null
+++ b/tests/t3/debian/control
@@ -0,0 +1,19 @@
+Source: foo
+Section: python
+Priority: optional
+Maintainer: Piotr Ożarowski <piotr@debian.org>
+Build-Depends: debhelper (>= 7.0.50~), python-all-dev
+Standards-Version: 3.9.1
+X-Python-Version: >= 2.6
+
+Package: python-foo
+Architecture: any
+Depends: ${python:Depends}, ${shlibs:Depends}, ${misc:Depends}
+Recommends: ${python:Recommends}
+Suggests: ${python:Suggests}
+Enhances: ${python:Enhances}
+Breaks: ${python:Breaks}
+Provides: ${python:Provides}
+XB-Python-Version: ${python:Versions}
+Description: foo to rule them all
+ exemple package #3 - Python extension
diff --git a/tests/t3/debian/copyright b/tests/t3/debian/copyright
new file mode 100644
index 0000000000000000000000000000000000000000..63829449e43c160582d21d7b484d145c0b2ac187
--- /dev/null
+++ b/tests/t3/debian/copyright
@@ -0,0 +1,2 @@
+The Debian packaging is © 2010, Piotr Ożarowski <piotr@debian.org> and
+is licensed under the MIT License.
diff --git a/tests/t3/debian/install b/tests/t3/debian/install
new file mode 100644
index 0000000000000000000000000000000000000000..380db416caf74384dede5d56c9782ad7c18bc40a
--- /dev/null
+++ b/tests/t3/debian/install
@@ -0,0 +1,2 @@
+# private module in architecture dependent dir
+lib/foo.py /usr/lib/python-foo/
diff --git a/tests/t3/debian/rules b/tests/t3/debian/rules
new file mode 100755
index 0000000000000000000000000000000000000000..1bba84bfdb97337e3a40331d0487e03a6a47c2bb
--- /dev/null
+++ b/tests/t3/debian/rules
@@ -0,0 +1,9 @@
+#!/usr/bin/make -f
+%:
+	dh $@ --buildsystem=python_distutils
+
+override_dh_pysupport:
+	# install also as private extension
+	dh_install debian/python-foo/usr/lib/`pyversions -d`/dist-packages/foo/bar.so \
+		/usr/lib/python-foo/
+	DH_VERBOSE=1 ../../dh_python2
diff --git a/tests/t3/debian/source/format b/tests/t3/debian/source/format
new file mode 100644
index 0000000000000000000000000000000000000000..89ae9db8f88b823b6a7eabf55e203658739da122
--- /dev/null
+++ b/tests/t3/debian/source/format
@@ -0,0 +1 @@
+3.0 (native)
diff --git a/tests/t3/lib/__init__.py b/tests/t3/lib/__init__.py
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/tests/t3/lib/bar.c b/tests/t3/lib/bar.c
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/tests/t3/lib/foo.py b/tests/t3/lib/foo.py
new file mode 100644
index 0000000000000000000000000000000000000000..11c51ef4ceb7b5fab75c7c076af274bc32e4b8a1
--- /dev/null
+++ b/tests/t3/lib/foo.py
@@ -0,0 +1,5 @@
+import foo.bar
+
+class Foo(object):
+    def __init__(self):
+        pass
diff --git a/tests/t3/setup.py b/tests/t3/setup.py
new file mode 100755
index 0000000000000000000000000000000000000000..4835818420ea65f889bac89f84e6d36bfff6a973
--- /dev/null
+++ b/tests/t3/setup.py
@@ -0,0 +1,13 @@
+#!/usr/bin/env python
+from distutils.core import setup, Extension
+setup(name="distutils-test",
+      version = "0.1",
+      author="jbailey",
+      author_email="jbailey@debian.org",
+      url="http://www.python.org/sigs/distutils-sig/",
+      ext_modules=[Extension('foo/bar', ['lib/bar.c'])],
+      #py_modules=['package'],
+      packages = ["foo"],
+      package_dir = {'foo': 'lib'}
+     )
+