Make python segfault in three lines

I think this is probably the fastest.

$ docker run -ti python:3.8-slim bash
# pip install mysql-connector-python==8.0.20
# python
>>> import random
>>> import mysql.connector
Segmentation fault

What is happening?

Premise

mysql-connector-python now bundles libcrypto.so.1.1 and libssl.so.1.1 from 8.0.20.

$ pip show -f mysql-connector-python  | grep lib
Location: /usr/local/lib/python3.8/site-packages
  mysql-vendor/libcrypto.so.1.1
  mysql-vendor/libssl.so.1.1

Commentary

import random

Importing random will load libcrypto.so.1.1. At this time, load libcrypto.so.1.1 installed on the system.

import mysql.connector

This import statement attempts to load libssl.so.1.1 and libcrypto.so.1.1. At that time, libssl.so.1.1 loads its own bundled one, libcrypto.so.1.1 is already loaded and will not be loaded.

Therefore, the situation is as follows.

libcrypto.so.1.1 --> /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1
libssl.so.1.1 --> /usr/local/lib/python3.8/site-packages/mysql-vendor/libssl.so.1.1

Since libcrypto.so.1.1 is incompatible, it causes a segmentation fault.

It has already been reported as a bug. https://bugs.mysql.com/bug.php?id=97220

Workaround

  1. Load /usr/local/lib/python3.8/site-packages/mysql-vendor/libssl.so.1.1 etc. with LD_PRELOAD
  2. Use a version earlier than 8.0.19.

Postscript

I found that it segfaults without loading random separately.

>>> import mysql.connector
Segmentation Fault

The above reasoning cannot be explained a little, so there seems to be another cause. I think it's certain that there is something wrong with the loading order in the bundled library as it can be avoided with LD_PRELOAD.

By the way, strangely, it happens in the python: 3.8-slim image, but not in the python: 3.8 image.

Recommended Posts

Make python segfault in three lines
Make python segfault in 2 lines
Make python segfault in one line
[Python 3] Prime factorization in 14 lines
Don't make test.py in Python!
Make Opencv available in Python
Python install in 2 lines @Windows
Make standard output non-blocking in Python
Make ASCII art GIF animation in Python
Line graphs and scale lines in python
Let's make a combination calculation in Python
Make cron-like jobs run regularly in Python
Quadtree in Python --2
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Discord in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Draw contour lines that appear in textbooks (Python)
Make a copy of the list in Python
Make a rock-paper-scissors game in one line (python)
Let's make some notification processing samples in Python
Make a joyplot-like plot of R in python
How to make Python Interpreter changes in Pycharm
Sorted list in Python
Daily AtCoder # 36 in Python
Clustering text in Python
Daily AtCoder # 2 in Python