freetype icon indicating copy to clipboard operation
freetype copied to clipboard

Index out of range

Open Arm1stice opened this issue 7 years ago • 3 comments

I had a panic occur in production today, this could be related to some of the bugs found in #17. It appears to stem from

https://github.com/golang/freetype/blob/e2365dfdc4a05e4b8299a783240d4a7d5a65d4e4/truetype/glyph.go#L331

The stack trace is attached below chrome_2018-09-12_13-48-53

I am not sure exactly what produced this bug, and normally the function that gets run doesn't produce this error. However, this could be an indication that there needs to be some checking before assuming that the offset is a valid index?

Arm1stice avatar Sep 12 '18 20:09 Arm1stice

We see the same issue in Fyne using the Google Noto Sans fonts. The int16() func is called with an offset that is right at the end of the array and so the +1 fails. What I cannot fathom is why this only happens some times. In theory the font and the rendering never changes. Recent reports seem to indicate it could be a race caused when this is called very frequently...

andydotxyz avatar Jan 29 '19 08:01 andydotxyz

I'm pretty sure that code is not thread-safe! I got a lot of random crashing due to races until adding mutexes upstream to ensure only one routine was calling at a time. it re-loads things into shared buffers I think..

rcoreilly avatar Jan 29 '19 18:01 rcoreilly

I had the same problem (index errors and garbled output in a high frequence rendering scenario). It completely disappeared after making the client code thread safe by using an object pool (https://github.com/jolestar/go-commons-pool) for the font instances.

jandelgado avatar Aug 23 '22 08:08 jandelgado