Skip to content
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

OSError: invalid face handle #3066

Closed
eroux opened this issue Apr 2, 2018 · 48 comments
Closed

OSError: invalid face handle #3066

eroux opened this issue Apr 2, 2018 · 48 comments
Labels
Anaconda Issues with Anaconda's Pillow Bug Any unexpected behavior, until confirmed feature. Fonts Platform A catchall for platform-related
Projects

Comments

@eroux
Copy link

eroux commented Apr 2, 2018

What did you do?

I ran the following code:

from PIL import Image, ImageDraw, ImageFont, features

print(features.check('raqm'))
print(Image.PILLOW_VERSION)

img = Image.new('RGB', (800, 300), color = (73, 109, 137))
d = ImageDraw.Draw(img)
fnt = ImageFont.truetype('NotoSansTibetan-Regular.ttf', 24, layout_engine=ImageFont.LAYOUT_BASIC)
d.text((10, 10), "༄༅། །སྒྲུབ།", font=fnt, fill=(255, 255, 0))
img.save('result.png')
fnt = ImageFont.truetype('NotoSansTibetan-Regular.ttf', 24, layout_engine=ImageFont.LAYOUT_RAQM)
print("things work until...")
res = fnt.getmask("༄༅། །སྒྲུབ།", features=['ccmp', 'abvs', 'blws', 'calt', 'liga', 'kern', 'abvm', 'blwm', 'mkmk'])

What did you expect to happen?

No segfault

What actually happened?

Here's the console output:

True
5.0.0
things work until...
Traceback (most recent call last):
  File "testmarche.py", line 13, in <module>
    res = fnt.getmask("༄༅། །སྒྲུབ།", features=['ccmp', 'abvs', 'blws', 'calt', 'liga', 'kern', 'abvm', 'blwm', 'mkmk'])
  File "/usr/local/lib/python3.5/dist-packages/PIL/ImageFont.py", line 163, in getmask
    return self.getmask2(text, mode, direction=direction, features=features)[0]
  File "/usr/local/lib/python3.5/dist-packages/PIL/ImageFont.py", line 166, in getmask2
    size, offset = self.font.getsize(text, direction, features)
OSError: invalid face handle
Erreur de segmentation

What versions of Pillow and Python are you using?

@wiredfool
Copy link
Member

What platform are you on?

@eroux
Copy link
Author

eroux commented Apr 2, 2018

Linux, up-to-date Debian stable

@wiredfool
Copy link
Member

It's happening OMM, OSX 10.12.6, from binary osx wheels of 5.1.0

============================================= FAILURES ==============================================
_________________________ TestImageFont_RaqmLayout.test_font_with_filelike __________________________

self = <test_imagefont.TestImageFont_RaqmLayout testMethod=test_font_with_filelike>

    def test_font_with_filelike(self):
        ImageFont.truetype(self._font_as_bytes(), FONT_SIZE,
                           layout_engine=self.LAYOUT_ENGINE)
>       self._render(self._font_as_bytes())

Tests/test_imagefont.py:109: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Tests/test_imagefont.py:123: in _render
    ttf.getsize(txt)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <PIL.ImageFont.FreeTypeFont object at 0x10fd88090>, text = 'Hello World!', direction = None
features = None

    def getsize(self, text, direction=None, features=None):
>       size, offset = self.font.getsize(text, direction, features)
E       IOError: invalid face handle

../vpy27-test/lib/python2.7/site-packages/PIL/ImageFont.py:157: IOError
1 failed, 874 passed, 41 skipped in 50.48 seconds

@eroux
Copy link
Author

eroux commented Apr 4, 2018

@khaledhosny any hint on where it could come from? Is there a "safer" commit/release of raqm that should be used?

@khaledhosny
Copy link

I don’t see where Raqm is involved here, invalid face handle is an error from FreeType, probably somewhere is passing an invalid FT_Face to Raqm.

@eroux
Copy link
Author

eroux commented Apr 4, 2018

I see... thanks for taking a look!

@hugovk

This comment has been minimized.

@hugovk hugovk closed this as completed Apr 10, 2018
@eroux

This comment has been minimized.

@hugovk

This comment has been minimized.

@hugovk hugovk reopened this Apr 10, 2018
@navenduagarwal
Copy link

did anyone find a solution, for me this error started happening as soon in installed depends/install_raqm.sh

@aclark4life aclark4life added the Bug Any unexpected behavior, until confirmed feature. label Jun 30, 2018
@johngsk
Copy link

johngsk commented Jul 13, 2018

Also having this issue. It's also inconsistent. Sometimes my script completes with no error and sometimes throws this OSError (seemingly a random string in the array of strings I am drawing each time) then crashes.

@ghost
Copy link

ghost commented Jan 25, 2019

Just started having this issue

Minimal code to reproduce:

from PIL import ImageFont

font = ImageFont.truetype("arial.ttf") # using arial as example, use any font you'd like
print(font.getsize("Hello World"))

@csoni111

This comment has been minimized.

@hugovk

This comment has been minimized.

@csoni111

This comment has been minimized.

@aclark4life aclark4life added the Platform A catchall for platform-related label May 11, 2019
@aclark4life aclark4life added this to Backlog in Pillow May 11, 2019
@aclark4life aclark4life moved this from Backlog to In progress in Pillow May 11, 2019
@aclark4life aclark4life moved this from In progress to Backlog in Pillow May 12, 2019
@chaitusvk
Copy link

chaitusvk commented Jul 1, 2019

getting error running with raqm how to resolve

code:

from PIL import Image, ImageDraw, ImageFont

img = Image.new('RGB', (800, 300), color = (73, 109, 137))
d = ImageDraw.Draw(img)
fnt = ImageFont.truetype('NotoSansTibetan-Regular.ttf', 24, layout_engine=ImageFont.LAYOUT_RAQM)
d.text((10, 10), "༄༅། །སྒྲུབ།", font=fnt, fill=(255, 255, 0))
img.save('result.png')

error

OSError                                   Traceback (most recent call last)
<ipython-input-1-b49c34b3a535> in <module>()
      4 d = ImageDraw.Draw(img)
      5 fnt = ImageFont.truetype('NotoSansTibetan-Regular.ttf', 24, layout_engine=ImageFont.LAYOUT_RAQM)
----> 6 d.text((10, 10), "༄༅། །སྒྲུབ།", font=fnt, fill=(255, 255, 0))
      7 img.save('result.png')

/usr/local/lib/python3.5/dist-packages/PIL/ImageDraw.py in text(self, xy, text, fill, font, anchor, *args, **kwargs)
    273             try:
    274                 mask, offset = font.getmask2(text, self.fontmode,
--> 275                                              *args, **kwargs)
    276                 xy = xy[0] + offset[0], xy[1] + offset[1]
    277             except AttributeError:

/usr/local/lib/python3.5/dist-packages/PIL/ImageFont.py in getmask2(self, text, mode, fill, direction, features, language, *args, **kwargs)
    183     def getmask2(self, text, mode="", fill=Image.core.fill, direction=None,
    184                  features=None, language=None, *args, **kwargs):
--> 185         size, offset = self.font.getsize(text, direction, features, language)
    186         im = fill("L", size, 0)
    187         self.font.render(text, im.id, mode == "1", direction, features, language)

OSError: invalid face handle

@Belval
Copy link

Belval commented Jul 7, 2019

Hi, I have the same issue, it seems that downloading libraqm on Ubuntu 18.04 changes the Pillow installation, and cause this issue with non latin fonts. Even when removing it, the issue persists, and I have not been able to generate text without having it raise the exception.

When doing the same thing with a clean OS install, the error does not happen until I reinstall libraqm at which point I am back in a broken state.

Is there a known fix for this?

@radarhere
Copy link
Member

@Belval since you've been dedicated enough to try this on a clean OS, could you provide step-by-step instructions on how to replicate?

@eroux
Copy link
Author

eroux commented Jul 19, 2019

are there people around who can't reproduce the issue?

@radarhere
Copy link
Member

I can't replicate on my macOS Mojave, or on Ubuntu 18.04 on Travis CI.

@Belval
Copy link

Belval commented Jul 19, 2019

@radarhere would a Dockerfile work? I can put one together today if that helps.

@radarhere
Copy link
Member

That would be great, thanks.

@zhenglilei
Copy link

zhenglilei commented Jun 16, 2020

Another thing is to check if the error is due to the environment language setting

apt-get install -y locales
locale-gen en_US.UTF-8
export LC_ALL=en_US.UTF-8 

My error goes away after I set up en_US.UTF-8.

@nulano
Copy link
Contributor

nulano commented Sep 1, 2020

Reproduced on GHA: https://github.com/nulano/Pillow/actions/runs/234697378
I suspect this issue is caused by a mismatch in system FreeType and wheel FreeType ABI on the following lines:

Pillow/src/_imagingft.c

Lines 472 to 475 in 4174d42

if (!(*p_raqm.set_freetype_face)(rq, self->face)) {
PyErr_SetString(PyExc_RuntimeError, "raqm_set_freetype_face() failed.");
goto failed;
}

Edit: The logs expired, re-run with 8.0.1 added: https://github.com/nulano/Pillow/actions/runs/419599965
I also ran the function in a loop to reproduce #4225 as well (click through to individual jobs to see if they fail immediately or after a few iterations).

@bsde1234
Copy link

I also had this issue. Fixed by

pip uninstall pillow
python3 -m pip install -U https://github.com/python-pillow/Pillow/archive/master.zip

@Zverik
Copy link

Zverik commented Jan 2, 2021

Could we please have a fix for this in Pillow? As I see it, there are reported and verifiable segfaults in Pillow on a basic operation for three years, and a working fix has been suggested half a year ago. Still this has been neither fixed nor documented, and people from dozens of projects have to spend time googling the issue (see the stream of mentions above)? As I see it, simply changing the default value would work.

@wiredfool
Copy link
Member

@Zverik It's not a default value issue. The potential core underlying issue was identified in late November, and is a packaging/licensing issue where portions of the code will use the system Freetype library and portions using the packaged library.

@Zverik
Copy link

Zverik commented Jan 2, 2021

Oh, right, I see this error is also discussed in #4225 and the fix is drafted in #5062. Thanks for the tip @wiredfool, let's hope the fix works :)

Amjad50 added a commit to Amjad50/Fyp that referenced this issue Mar 13, 2021
Not sure why it is producing this error, but this solution fixed it.

source:
python-pillow/Pillow#3066 (comment)
@radarhere
Copy link
Member

The proposed fix has been merged, so this should be retested when Pillow 8.2.0 is released.

@radarhere
Copy link
Member

Pillow 8.2.0 has now been released.

@Codeize
Copy link

Codeize commented Apr 2, 2021

@radarhere Fixed the issue it seems, thanks!

@hugovk hugovk closed this as completed Apr 2, 2021
Pillow automation moved this from Backlog to Closed Apr 2, 2021
@khaledmsm
Copy link

khaledmsm commented Aug 15, 2022

i have a problem with pillow, when i'm trying to paste image it doesn't showing in images

@radarhere
Copy link
Member

Your problem doesn't seem related to this issue. If you could open a new issue with a self-contained example, so that we can run the same code that you are running, that would be helpful.

maxfrei750 added a commit to maxfrei750/paddle that referenced this issue Sep 2, 2022
tkeffer added a commit to weewx/weewx that referenced this issue Feb 21, 2023
Without the workaround, you can get a segmentation fault.
See python-pillow/Pillow#3066
@aclark4life aclark4life added the Anaconda Issues with Anaconda's Pillow label May 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Anaconda Issues with Anaconda's Pillow Bug Any unexpected behavior, until confirmed feature. Fonts Platform A catchall for platform-related
Projects
Pillow
  
Closed
Development

No branches or pull requests