Ghostscript built with FT_BRIDGE support gets segmentation fault when TrueType CID fonts are specified. How to repeat: Install print/ghostscript-gpl with FT_BRIDGE option and japanese/ipa-ttfonts on FreeBSD. Configure FAPIcidmap to use /usr/local/share/ghostscript/fonts/Ryumin-Light.ttf with /FAPI /FreeType option for /Ryumin-Light font. Download http://www.sens.ee.saga-u.ac.jp/wakuya/paper/ieice-9401-d2.ps.gz and gunzip it. Run gs ieice-9401-d2.ps, then your gs will crash. Crash cause: This segfault is caused by TT_char_code_from_CID_no_subst() calling array_get() without checking TT_cmap value. Its value may be NULL because FAPI_do_char() calls cid_to_TT_charcode() with NULL TT_cmap parameter.
Created attachment 3991 [details] Sample fix I don't think this sample fix is complete because I get so many warnings like this: GPL Ghostscript 8.62: Warning : Cropping a FAPI glyph while caching : dx=103157003,103156971.
I'm sorry, above sample postscript file does not cause the segfault. Please download http://www.math.nagoya-u.ac.jp/~shoji/papers/tut3.ps instead.
This requires a FreeType development, so I suggest to close as wontfix. Passing to Henry. There is no real demand on the FreeType plugin to Postscript or PDF..
leonardo in #3 states correctly we are not supporting the freetype bridge. Hiroto, can you tell us the motivation for using the freetype bridge instead of the default configuration? Also I compiled gs with the latest freetype and had to set an option in the freetype configuration for it to to work at all (use the plugin) and even simple files like examples/alphabet.ps did not work properly. If you want us to look at your patch please provide exact build instruction (compile settings, version numbers, etc.)
Thanks for comments. My motivation for using freetype bridge is its rendering performance especially for CJK text. In fact, for example, above tut3.ps is rendered 1.7x faster than normal configuration. On my Core 2 Duo E6600 FreeBSD 7.0-RELEASE PC: ### FT version ### $ time gs -dNOPAUSE tut3.ps </dev/null ... real 0m4.480s user 0m3.621s sys 0m0.417s ### normal version ### $ time gs -dNOPAUSE tut3.ps </dev/null ... real 0m7.501s user 0m6.508s sys 0m0.540s Build instruction on FreeBSD 7.0: (I'm sorry if you are not familiar with FreeBSD; I'm not using Linux) # cd /usr/ports/japanese/ipa-ttfonts # make install clean This installs Japanese fonts. # cd /usr/ports/print/ghostscript8 # make config and select FT_BRIDGE option. # make install This builds and installs ghostscript as well as dependent libraries including freetype 2.3.7 (no special configuration options are required). # vi /usr/local/share/ghostscript/8.62/lib/FAPIcidfmap Uncomment /Ryumin-Light and /GhothicBBB-Medium lines, add fullpath (/usr/local/share/ghostscript/fonts) to truetype fonts, and change /UFST to /FreeType for the both lines. Then you can run gs. Of course, /usr/ports/x11/xorg should be installed and configured properly to run gs on the local console, or otherwise you should be able to run gs remotely. If you want to modify source code, # cd /usr/ports/print/ghostscript # make deinstall clean patch # vi work/any/file # make install Thank you.
I have copied in leo so he will note the performance discrepancy. Regarding the configuration, the pristine freetype from http://download.savannah.gnu.org requires enabling the definition FT_CONFIG_OPTION_INCREMENTAL. Here is the snippet from freetype's ftoption.h file. /*************************************************************************/ /* */ /* Allow the use of FT_Incremental_Interface to load typefaces that */ /* contain no glyph data, but supply it via a callback function. */ /* This allows FreeType to be used with the PostScript language, using */ /* the GhostScript interpreter. */ /* */ /* #define FT_CONFIG_OPTION_INCREMENTAL */ I suppose the freebsd scripts handles this but I am not sure other distributions or developers know how to do this, I didn't and I spent some time poking around to solve the problem. We'll discuss getting your fix or an equivalent change integrated.
For what it's worth, I was finally able to reproduce the segfault, after downloading the ipa fonts manually and pointing at them with FAPIcidfmap. This is with today's work-in-progess freetype git branch (based on svn r9470 built against freetype 2.3.8 with incremental font and tracing enabled. partial backtrace: #0 0x00000000004b3bcd in dict_find (pdref=0x0, pkey=0x7fff4a5e9f20, ppvalue=0x7fff4a5e9f40) at ./psi/idict.c:86 #1 0x0000000000417746 in TT_char_code_from_CID_no_subst (mem=0x166c818, Decoding=0x176bc80, TT_cmap=0x0, nCID=887, c=0x7fff4a5ea210) at ./psi/zcid.c:75 #2 0x00000000004177ec in cid_to_TT_charcode (mem=0x166c818, Decoding=0x176bc80, TT_cmap=0x0, SubstNWP=0x176bc90, nCID=887, c=0x7fff4a5ea210, src_type=0x7fff4a5ea1c0, dst_type=0x7fff4a5ea1b0) at ./psi/zcid.c:95 #3 0x00000000005b9206 in FAPI_do_char (i_ctx_p=0x16aafb8, pbfont=0x175ec70, dev=0x16e4fd8, font_file_path=0x210c04b "./ipag.ttf", bBuildGlyph=1, charstring=0x0) at ./psi/zfapi.c:1416 #4 0x00000000005ba663 in FAPI_char (i_ctx_p=0x16aafb8, bBuildGlyph=1, charstring=0x0) at ./psi/zfapi.c:1752 #5 0x00000000005ba85a in zFAPIBuildGlyph (i_ctx_p=0x16aafb8) at ./psi/zfapi.c:1792
FAPI_do_char is explicitly passing NULL for TT_cmap. I'm not clear what it's supposed to do instead. If the call is bypassed the font just doesn't get rendered.
In r9531 I committed a partial fix. The file now throws an invalid font error instead of a segmentation fault. The font file itself is fine, however. Other code in Ghostscript isn't constructing the CID font correctly.
This is now (finally!) fixed in revision 9574, patch here: http://ghostscript.com/pipermail/gs-cvs/2009-March/009148.html Please note however that this also relies upon revision 9572 which must be installed first: http://ghostscript.com/pipermail/gs-cvs/2009-March/009146.html and I would also recommend adding the patch for revision 9573. More changes to the FreeType bridge code are anticipated in the near future.
Revision 9583 fixes the remaining known issues with the FreeType bridge code, patch here: http://ghostscript.com/pipermail/gs-cvs/2009-March/009157.html As noted earlier, this relies on prior fixes, you must install all of them. It is probably much easier just to use the HEAD revision.