-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Crash with an error: munmap_chunk(): invalid pointer #4225
Comments
How many iterations of the loop does it take to reproduce the problem? |
@radarhere 28 iterations. Interesting fact: when I changed the code to: import PIL.Image
import PIL.ImageDraw
import PIL.ImageFont
i = 0
while True:
i += 1
print(i)
image = PIL.Image.new("RGBA", (10, 10))
draw = PIL.ImageDraw.Draw(image)
font = PIL.ImageFont.truetype("Arial.ttf", 12)
print(draw.multiline_textsize("Sample", font=font)) it start to crash on 218 iteration. |
I can confirm the issue (which is apparently the same) on:
I can reproduce the issue above using the code above. Also, the results below only serve as a confirmation but don't offer new information other than that different types of crashes ("heisenbugs") causing core dumps occur intermittently in practical use. detailsIt is hard to reproduce in my case. Considering the original issue report above, the reason mine is hard to reproduce may be that in my library I only load the font object once then cache it (I cache the return of ImageFont.truetype):I could get any of the following, but always when using the font to draw (on
or 2.
or 3.
|
I have this problem too, but it only happened if I install Pillow from wheel file or just run pip install Pillow, which will use wheel file by default. If I install with this command My environment: Fedora 31, Python 3.6 (in venv), Pillow 7.0.0 |
I note Fedora is a common factor in these three reports. |
It also happened on CentOS 8 too, the problem also gone if I install from source instead of wheel file. |
Another Fedora 31 user here with the same issue. CentOS 8 is based off Fedora 28 (like RHEL 8) so I suspect this might affect older Fedora versions. That or something's been backported. As with @cwt, installing the non-binary package ( Edit: For anyone else stumbling upon this, I needed to install the following packages to build things correctly:
|
I'm experiencing the same problem on Debian. The original code example crashes on the third iteration here (though with another font: Vera.ttf).
|
I have the same problem on Arch Linux using a Verdana.ttf font.
Solved with compiling myself |
Still an issue in 8.0.1. on Python 3.8.6. OS Archlinux, x86_64. from PIL import Image, ImageDraw, ImageFont
for try_n in range(100):
print(try_n+1)
text = "TEXT"
img = Image.new("RGBA", (100, 100))
draw = ImageDraw.Draw(img)
font = ImageFont.truetype("/usr/share/fonts/liberation/LiberationSerif-Regular.ttf", 15)
draw.text((5,5), text, font=font) Fails consistently on the 3rd try. Font Size or actual text don't matter. If the font is removed, it works. Issue persists with different fonts, although it fails on different tries for each font (but is still consistent for every font I tried, i.e., NimbusSans-Regular fails on second attempt). Noteworthy: Works flawlessly on Raspberry Pi 3! |
I also got this issue
It happens randomly but mostly on 3rd or 4th iteration. |
Also confirm the issue.
|
Recent reporters, are you doing this with the shipped wheels or did you compile yourself? |
Shipped. Works fine with |
Yup, shipped from PyPI |
Ok, I can replicate this on Ubuntu 20.04 with the shipped image. Of course, it doesn't do it with builds on that machine. It does appear that there's something funky going on with the Font Face references through raqm/harfbuzz/freetype. I'm seeing invalid read/writes on:
which leads to:
And then it fails with a Segfault. This doesn't happen with a locally compiled version here, nor does valgrind trigger on anything in PIL. I've got all of the dependencies installed here, so we have the all of the same dependencies, though not necessarily the same versions. Stepping through, they appear to be following the same code paths. In the production versions, it's not clear that the font faces are invalid, but enough of the code has been optimized out that I'm not sure that things are behaving correctly or not. But they're not obviously wrong. So a few things need to happen to narrow this down.
|
If this is only happening with Raqm, I wonder if it is related to #3066, which I'm pretty sure is caused by the way Raqm is loaded dynamically, but FreeType compiled in statically. If so, one possible solution I have been thinking about could be to include Raqm in wheels but modify it to use a shim to load FriBiDi dynamically, similarly to how #2753 links Raqm. That would also allow dropping support code for old Raqm versions. Including Raqm statically would avoid passing FreeType structs between different builds of FreeType, and the FriBiDi interface only passes objects for the FriBiDi library. FriBiDi should also be more widely available (it is a dependency of Raqm, so it should be everywhere where there is Raqm). |
It is happening with RAQM, but it's also not happening with RAQM. It's the particular build of it that's the issue. But I do agree that the issue is likely the same as #3066. It's possible that dynamically linking fribidi would work, but I haven't looked at how complicated that interface is. |
I meant "If a workaround is to use
I just had a brief look and I think it might even be simpler than the Raqm interface. I don't see any structs being passed, only typedef-ed ints. There is also one large enum, but the single required value can be hardcoded. There is a single FriBiDi related
|
I can also confirm the issue.
|
Confirming
|
Can you try the wheels from the end of pr #5062 ? |
Until python-pillow/Pillow#4225 gets resolved. You can check simply by running corpy's test suite, that triggers the segfault fairly reliably.
I can also confirm the issue.
fixed by : |
@nulano I can confirm this fixes the issue for me. |
A proposed fix has been merged, so this should be retested when Pillow 8.2.0 is released. |
Pillow 8.2.0 has now been released. |
@catcombo are you in a position to check this? |
@radarhere I run the test code and it looks the bug is fixed. Thank you! |
Older versions give the error: munmap_chunk(): invalid pointer Or, corrupted size vs. prev_size See python-pillow/Pillow#4225
What did you do?
I was faced a problem when using arcade library. It uses
Pillow
under the hood to work with images. When I tried to draw game score text, I got random crash. I localized the problem and found out that crash is related to the way thePillow
works with font and frees up a resources.What actually happened?
Crash with an error:
What are your OS, Python and Pillow versions?
Code example
Crashing code example (munmap_chunk(): invalid pointer):
Works without any problem:
The text was updated successfully, but these errors were encountered: