Bug 2527047 - calibre redirects Cryptodome imports to Crypto but has no pycryptodome dependency — breaks py7zr and pycryptodome-using code on Fedora
Summary: calibre redirects Cryptodome imports to Crypto but has no pycryptodome depend...
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: calibre
Version: 44
Hardware: x86_64
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Kevin Fenzi
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2026-09-01 20:16 UTC by Florian Wallner
Modified: 2026-10-31 18:28 UTC (History)
5 users (show)

Fixed In Version: calibre-9.15.0-1.fc45
Clone Of:
Environment:
Last Closed: 2026-10-31 18:28:58 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Florian Wallner 2026-09-01 20:16:54 UTC
Fedora's calibre installs a meta-path import hook (DeVendor in calibre/constants.py) that rewrites every Cryptodome.* import to Crypto.*:

if fullname.startswith('Cryptodome'):
    # this is needed for py7zr which uses pycryptodomex instead of
    # pycryptodome for some reason
    return ModuleSpec(fullname, DeVendorLoader(fullname.replace('dome', '', 1)))

This assumes the Crypto namespace is provided by pycryptodome. On Fedora that assumption does not hold:

- Fedora packages pycryptodome only as python3-pycryptodomex, which provides the Cryptodome namespace — never the Crypto namespace.
- The Crypto namespace is provided by python3-crypto (PyCrypto 2.6.1), an unmaintained library that lacks large parts of the pycryptodome API (e.g. RSA.import_key).
- The calibre package declares no dependency on any Python crypto package (only libcrypto.so.3 from OpenSSL).

Consequently, inside calibre import Cryptodome does not load pycryptodome. Depending on what is installed:

- If python3-crypto is present, Cryptodome.* resolves to PyCrypto 2.6.1. Code using the pycryptodome API then fails, e.g.
  AttributeError: module 'Crypto.PublicKey.RSA' has no attribute 'import_key'. Did you mean: 'importKey'?
- If python3-crypto is absent, the redirect targets a nonexistent Crypto and raises
  ModuleNotFoundError: No module named 'Crypto'.

Either way, any calibre code path importing Cryptodome (py7zr-based 7z handling, and third-party plugins that use pycryptodome) is broken.


Reproducible: Always

Steps to Reproduce:
1.Fedora 44 with calibre-9.13.0-1.fc44, python3-pycryptodomex-3.23.0-5.fc44, and python3-crypto-2.6.1-60.fc44 installed.
2. calibre-debug -c "import Cryptodome; print(Cryptodome.__file__, Cryptodome.version_info)"
3. Compare: /usr/bin/python3 -c "import Cryptodome; print(Cryptodome.__file__, Cryptodome.version_info)"
Actual Results:
- calibre resolves import Cryptodome to /usr/lib64/python3.14/site-packages/**Crypto**/__init__.py — i.e. the Crypto namespace, not Cryptodome. With python3-crypto installed this is PyCrypto version_info (2, 6, 1, 'final', 0), whose Crypto.PublicKey.RSA has no import_key (only the legacy importKey).
- System python resolves import Cryptodome correctly to /usr/lib64/python3.14/site-packages/**Cryptodome**/__init__.py (pycryptodome 3.23.0).

Expected Results:
Inside calibre, import Cryptodome should load the real pycryptodome (python3-pycryptodomex, version 3.x), so py7zr and pycryptodome-using code work.

Additional Information:
The Cryptodome→Crypto redirect is correct for upstream calibre, which bundles pycryptodome under the Crypto name. On Fedora, calibre is de-vendored and the real python3-pycryptodomex (Cryptodome) is present, so the redirect is actively harmful. Suggested options:

1. Preferred: drop/patch out the Cryptodome→Crypto branch of the DeVendor hook in the Fedora build and add Requires: python3-pycryptodomex, so Cryptodome imports use the system package directly.
2. Alternatively, require a package that provides pycryptodome under the Crypto namespace (Fedora currently ships none).

Note also that python3-crypto (PyCrypto 2.6.1) is unmaintained (last release 2013) and silently mis-satisfies the Crypto namespace here.

Workaround (local): remove python3-crypto and expose the RPM's pycryptodome under the Crypto name:
sudo dnf remove python3-crypto
site=$(/usr/bin/python3 -c 'import os,Cryptodome; print(os.path.dirname(os.path.dirname(Cryptodome.__file__)))')
sudo ln -sfn Cryptodome "$site/Crypto"

Comment 1 Florian Wallner 2026-09-01 20:25:50 UTC
Additional context on why python3-crypto is present, since the obvious response might be "just uninstall it":

On this system python3-crypto was never installed manually — it comes in purely as a weak dependency. python3-beaker has Recommends: python3-crypto, and python3-beaker is itself pulled in transitively (here: rhythmbox → python3-mako → python3-beaker). The Fedora 41→42 system-upgrade transaction records python3-crypto with reason "Weak Dependency", and it predates my local dnf5 history entirely, so it has been carried along across releases.

The relevant point for this bug: because Fedora installs Recommends by default, the unmaintained PyCrypto 2.6.1 (which owns the Crypto namespace) ends up on ordinary desktop installs without any unusual user action — in my case dragged in by a music player. So calibre's Cryptodome→Crypto redirect silently resolves to the wrong, API-incomplete library on a broad range of systems, not just niche setups.

Verification:

$ dnf repoquery --whatrecommends python3-crypto
python3-beaker-0:1.12.1-14.fc44.noarch

$ dnf5 history info <F41→F42 upgrade tx> | grep python3-crypto
  Upgrade   python3-crypto-0:2.6.1-54.fc42.x86_64   Weak Dependency   fedora

This reinforces the suggested fix: calibre should depend on python3-pycryptodomex and use the Cryptodome namespace directly rather than redirecting to Crypto, whose provider on Fedora is not guaranteed to be pycryptodome.

Comment 2 Kevin Fenzi 2026-09-08 23:31:36 UTC
Ah, thanks for all the detective work. ;( 

I agree we should patch/drop out that devendor hook and add the dep. 

Would you be willing to do a pr? 

If not I will try and get to it when I can...

Comment 3 Florian Wallner 2026-09-09 08:52:57 UTC
Let me try.

Comment 4 Florian Wallner 2026-09-09 18:01:18 UTC
I managed to create a PR on dist-git (https://src.fedoraproject.org/rpms/calibre/pull-request/21). My first one, very exciting. Thank you for your guidance and for the quick response on this!

Comment 5 Fedora Update System 2026-10-04 18:38:01 UTC
FEDORA-2026-056e5952ce (calibre-9.15.0-1.fc45) has been submitted as an update to Fedora 45.
https://bodhi.fedoraproject.org/updates/FEDORA-2026-056e5952ce

Comment 6 Fedora Update System 2026-10-05 01:54:51 UTC
FEDORA-2026-056e5952ce has been pushed to the Fedora 45 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2026-056e5952ce`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2026-056e5952ce

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 7 Fedora Update System 2026-10-31 18:28:58 UTC
FEDORA-2026-056e5952ce (calibre-9.15.0-1.fc45) has been pushed to the Fedora 45 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.