golang/freetype

Index out of range

Arm1stice opened this issue · 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

dy := int16(glyf[offset])

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?

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...

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..

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.