golang / freetype

The Freetype font rasterizer in the Go programming language.
Other
778 stars 183 forks source link

Index out of range #65

Open Arm1stice opened 5 years ago

Arm1stice commented 5 years ago

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?

andydotxyz commented 5 years ago

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

rcoreilly commented 5 years ago

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

jandelgado commented 1 year ago

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.