-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: Coredump when importing matplotlib.pyplot #25823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is somewhat surprising. I can state that my main dev machine has It is true that non-scalable fonts are not supported by Matplotlib, but there is handling python-side for rejecting such fonts (though that is after calling into the ft2font cpp library). |
But with what version of FreeType? |
The only thing in |
The version of FreeType is 2.10.4
Here is the size of the NotoColorEmoji.ttf file for reference $ ls -l /usr/share/fonts/google-noto-emoji/NotoColorEmoji.ttf I have checked this in 5+ different machines, and the only one which works is the 7.3 machine without the NotoColorEmoji font. All others are using RH7.6. I'll check on some other RH8 machines. |
Some more debugging, but I'm not clear on how this is an issue; In
"Could not set the fontsize (invalid pixel size; error code 0x17)"
FT2Font::FT2Font was called from within the CALL_CPP_FULL macro as @QuLogic pointed out, which does have a try/catch block and explicitly catches std::runtime_error (+ has a catch all as well).
The only strange thing I see is that when these files are compiled, gcc is being used as opposed to g++. It looks like gcc does recognize .cpp as a C++ extension and has no issue compiling the code, but I wonder if there is some impact on exception handling from doing this? I tried forcing g++ by setting CC but this led to other issues with C code that could not be compiled by g++. |
I manually compiled the ft2font related files with g++ and it made no difference, also used GCC 12.2.0 and still a crash. |
I went back to try and figure out the difference between 3.1.3 which was working and 3.4.3/3.6.1, ... It looks like the issue is related to some compiler options. If I remove the |
The issue seems to be the addition of |
Hi, I'm not really going to go much further to see why LTO and exceptions are not playing well together. In the *setup.cfg.template file, there is an entry to disable LTO. Once I do this, the crashes in matplotlib disappear.
If someone wants to investigate further, then just setting
|
What version of GCC do you have? |
Even if I put the On import no error happens, though when trying to render text I get a This is without changing compiler options/etc. |
I'm using GCC 9.3 and I've also tried 12.2. I could try recompiling everything including Python with 12.2 and see what happens. |
I'm on gcc 11.3. When I use freetype 2.10.1 (the closest version we had SHA hash for already in When I use freetype 2.10.4/2.11.1 I initially got Full Diff:diff --git a/setupext.py b/setupext.py
index a91c681e0f..f981424ad5 100644
--- a/setupext.py
+++ b/setupext.py
@@ -176,13 +176,15 @@ _freetype_hashes = {
'955e17244e9b38adb0c98df66abb50467312e6bb70eac07e49ce6bd1a20e809a',
'2.10.1':
'3a60d391fd579440561bf0e7f31af2222bc610ad6ce4d9d7bd2165bca8669110',
+ '2.10.4':
+ '5eab795ebb23ac77001cfb68b7d4d50b5d6c7469247b0b01b2c953269f658dac',
'2.11.1':
'f8db94d307e9c54961b39a1cc799a67d46681480696ed72ecf78d4473770f09b'
}
# This is the version of FreeType to use when building a local version. It
# must match the value in lib/matplotlib.__init__.py, and the cache path in
# `.circleci/config.yml`.
-TESTING_VERSION_OF_FREETYPE = '2.6.1'
+TESTING_VERSION_OF_FREETYPE = '2.11.1'
if sys.platform.startswith('win') and platform.machine() == 'ARM64':
# older versions of freetype are not supported for win/arm64
# Matplotlib tests will not pass
@@ -644,7 +646,7 @@ class FreeType(SetupPackage):
configure = [
"./configure", "--with-zlib=no", "--with-bzip2=no",
"--with-png=no", "--with-harfbuzz=no", "--enable-static",
- "--disable-shared"
+ "--disable-shared", "--with-brotli=no",
]
host = sysconfig.get_config_var('HOST_GNU_TYPE')
if host is not None: # May be unset on PyPy.
diff --git a/src/ft2font.cpp b/src/ft2font.cpp
index 2e5d6e63b8..f56f65fabd 100644
--- a/src/ft2font.cpp
+++ b/src/ft2font.cpp
@@ -360,6 +360,7 @@ FT2Font::FT2Font(FT_Open_Args &open_args,
hinting_factor = hinting_factor_;
error = FT_Set_Char_Size(face, 12 * 64, 0, 72 * (unsigned int)hinting_factor, 72);
+ error = 23;
if (error) {
FT_Done_Face(face);
throw_ft_error("Could not set the fontsize", error);
|
I recompiled everything with GCC 12.2.0, also checked the top-level Python build to make sure it was linked with g++ (--with-cxx-main on configure commands). I updated to use the system FreeType (2.8.0). I'm not really sure what steps I would take next. For now I will just go with enable_lto=False, to resolve the issue. |
Can you reproduce this with 3.7.x or main? |
I'm going to close as an obscure compiler issue, but feel free to ask for a re-open. |
Bug summary
When I execute
python -c 'import matplotlib.pyplot'
, python will coredump. This will occur when it is generating the~/.cache/matplotlib/fontlist-v330.json
file, assuming that it was not already successfully generated.The root cause of the problem is that the
/usr/share/fonts/google-noto-emoji/NotoColorEmoji.ttf
font will cause aninvalid pixel size
exception to be thrown from the FreeType library, the exception is not subsequently handled in the C++ layer, and python will abort.Code for reproduction
Actual outcome
[1] 229645 abort (core dumped) python -c
Expected outcome
No output
Additional information
It appears that this is only caused by the NotoColorEmoji font. If I update font_manager.py to skip this font, there is no issue.
This was at least working in 3.1.3. I have tried 3.4.3 and 3.6.1 and they both have the same issue. I'm using system_freetype=True in the mplsetup.py file. I have also tried compiling FreeType and this does not seem to resolve anything.
The root cause of the problem is that the
/usr/share/fonts/google-noto-emoji/NotoColorEmoji.ttf
font will cause aninvalid pixel size
exception to be thrown from the FreeType library, the exception is not subsequently handled in the C++ layer, and python will abort.I am using RedHat 7.6, 7.3 works fine because it does not have the problematic font.
Here is a link to a similar issue using Pillow, issue. I'm not familiar with the code, but my understanding is that the correct solution would be the handle the FreeType exceptions in the ft2font_wrapper.cpp code and not propogate it into the Python interpreter.
Here is part of the stack trace.
Operating system
RedHat 7.6
Matplotlib Version
3.6.1
Matplotlib Backend
Call to getBackend also crashes (same reason as above)
Python version
3.9.16
Jupyter version
No response
Installation
None
The text was updated successfully, but these errors were encountered: