AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Informational 16 Bitcoin

android: add run-time patch to make pycryptodomex work

Public commit record

What the developer wrote

Authored by SomberNight

93/100 · Strong
android: add run-time patch to make pycryptodomex work

to work around https://github.com/kivy/python-for-android/issues/1866 :

> PyCryptodome >=3.6.0 crashes at runtime (since commit https://github.com/Legrandin/pycryptodome/commit/f5aa2c1618e97b6d773172fdd07794a0a6f05905). So actually the currently pinned version in the recipe does not work:
> https://github.com/kivy/python-for-android/blob/80e4f059c1ee0da48a7c85167087dfe5928ac395/pythonforandroid/recipes/pycryptodome/__init__.py#L5
>
> The issue at runtime is with ctypes.
>
>
> Say I have a main script that just does the following (https://github.com/Legrandin/pycryptodome/blob/95ccce7ae82d3a36f1a8652dd2c645222d0128dd/lib/Crypto/Util/_raw_api.py#L200):
> ```
> import ctypes
> ctypes.pythonapi.PyObject_GetBuffer
> ```
>
> This works with cpython on my laptop, but with the p4a-compiled python on Android it fails:
>
> ```
> 06-14 19:06:27.053 15246 15274 I python : Android kivy bootstrap done. __name__ is __main__
> 06-14 19:06:27.053 15246 15274 I python : AND: Ran string
> 06-14 19:06:27.053 15246 15274 I python : Run user program, change dir and execute entrypoint
> 06-14 19:06:27.092 15246 15274 I python : Traceback (most recent call last):
> 06-14 19:06:27.092 15246 15274 I python : File "/home/user/wspace/electrum/.buildozer/android/app/main.py", line 84, in <module>
> 06-14 19:06:27.093 15246 15274 I python : File "/home/user/wspace/electrum/.buildozer/android/platform/build/build/other_builds/python3-libffi-openssl-sqlite3/armeabi-v7a__ndk_target_21/python3/Lib/ctypes/__init__.py", line 369, in __getattr__
> 06-14 19:06:27.093 15246 15274 I python : File "/home/user/wspace/electrum/.buildozer/android/platform/build/build/other_builds/python3-libffi-openssl-sqlite3/armeabi-v7a__ndk_target_21/python3/Lib/ctypes/__init__.py", line 374, in __getitem__
> 06-14 19:06:27.094 15246 15274 I python : AttributeError: undefined symbol: PyObject_GetBuffer
> ```
>
> I have also tried to access some other attributes of `ctypes.pythonapi`, such as `Py_IncRef`, which raises the same exception.

---

Unclear if the issue still affects newer p4a: upstream seems to think it's fixed, but there multiple comments in the thread saying otherwise. Anyway, rebasing p4a has other blockers atm.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit adds a small Android-only workaround so that a cryptography library (pycryptodomex) can load correctly inside the Electrum mobile app. It replaces the way Python finds its own C API with an explicit path to the Python shared library. There is no direct security vulnerability here; it is a compatibility patch for a packaging/toolchain issue. However, it is a 'hack' that touches low-level Python internals, so it could in theory affect app stability or future updates.

Recommended action

Treat as a maintenance/compatibility patch rather than a security fix. Reviewers should verify that `libpython%d.%d.so` exists and is loadable on all supported Android ABIs and Python versions, and that the workaround does not interfere with other ctypes users. Consider removing the hack once python-for-android upstream definitively resolves issue #1866 and Electrum rebases to that p4a version.

Security signals we found

01

Low-level ctypes/pythonapi manipulation

02

Workaround for missing/undefined CPython symbols in Android build

03

Dependency on external shared library path derived from sys.version_info

04

No input validation or sanititation involved (not applicable to this patch)

Risk score

Why this scored 16/100

Our methodology →
Potential impact 2/30
Exploitability 1/25
Stealth signal 1/15
Affected reach 2/15
Confidence 7/10
Evidence quality 3/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.