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

Segfault when processing some fonts #19

Closed
wch opened this issue Jan 18, 2023 · 0 comments · Fixed by #20
Closed

Segfault when processing some fonts #19

wch opened this issue Jan 18, 2023 · 0 comments · Fixed by #20

Comments

@wch
Copy link
Owner

wch commented Jan 18, 2023

The change in #13 caused this message to be printed for some fonts when calling extrafont::font_import(). Here is a font that causes the problem:

FiraSans-Bold.ttf.zip

This is an example of the error message:

> font_import('foo', prompt=F)
Scanning ttf files in foo ...
Extracting .afm files from .ttf files...
/Users/winston/Projects/Rttf2pt1/foo/FiraSans-Bold.ttfsh: line 1: 75065 Segmentation fault: 11  '/Users/winston/R/4.1/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Users/winston/Projects/Rttf2pt1/foo/FiraSans-Bold.ttf' '/var/folders/vd/0_g4hj6d7kq_fw5gd_r0ml5w0000gn/T//Rtmp4zq4o9/fonts/FiraSans-Bold' 2>&1
 : No FontName. Skipping.
Found FontName for 0 fonts.
Scanning afm files in /Users/winston/R/4.1/extrafontdb/metrics
Warning message:
In system2(enc2native(ttf2pt1), c(args, shQuote(ttfiles[i]), shQuote(tmpfiles[i])),  :
  running command ''/Users/winston/R/4.1/Rttf2pt1/exec//ttf2pt1' -a -GfAe '/Users/winston/Projects/Rttf2pt1/foo/FiraSans-Bold.ttf' '/var/folders/vd/0_g4hj6d7kq_fw5gd_r0ml5w0000gn/T//Rtmp4zq4o9/fonts/FiraSans-Bold' 2>&1' had status 139

Notably, there was a Segmentation fault: 11 message which was easy to miss. Running with lldb, I saw this:

$ lldb -- ./src/ttf2pt1/ttf2pt1 -a -G fAe foo/FiraSans-Bold.ttf 
(lldb) target create "./src/ttf2pt1/ttf2pt1"
Current executable set to '/Users/winston/Projects/Rttf2pt1/src/ttf2pt1/ttf2pt1' (arm64).
(lldb) settings set -- target.run-args  "-a" "-G" "fAe" "foo/FiraSans-Bold.ttf"
(lldb) r
Process 75975 launched: '/Users/winston/Projects/Rttf2pt1/src/ttf2pt1/ttf2pt1' (arm64)
Using language 'latin1' for Unicode fonts
Auto-detected front-end parser 'ttf'
 (use ttf2pt1 -p? to get the full list of available front-ends)
Processing file foo/FiraSans-Bold.ttf
Some font name strings are in Unicode, may not show properly
numglyphs = 2708
Found Unicode Encoding
Process 75975 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x4000000000000000)
    frame #0: 0x0000000100014f54 ttf2pt1`fdotsegdist2(seg=0x000000016fdfe168, dot=0x000000016fdfe188) at pt1.c:5036:7
   5033		/* end of macro */
   5034	
   5035	
-> 5036		dx = x2 - x1;
   5037		dy = y2 - y1;
   5038	
   5039		if(fabs(dx) < FEPS) {
Target 0: (ttf2pt1) stopped.

I think the problem is that in #13, I changed the type of double seg[2][2] to double** seg, to avoid a false positive compiler warning. However, these types are not the interchangeable. double seg[2][2] can be replaced with double* seg[2], but these are not equivalent to double** seg.

The good news (I think) is that while the (spurious) warning existed in gcc 11, it is not present in gcc 12, at least if I understand this comment correctly:
https://stackoverflow.com/questions/69891976/gcc-11-gives-wstringop-overflow-when-no-string-operation-is-used#comment123547865_69891976

So hopefully CRAN is testing on gcc 12 and I can submit an updated version with these changes reverted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant