tomolt / libschrift

A lightweight TrueType font rendering library
ISC License
471 stars 32 forks source link

Stack overflow in render_outline due to 256KB stack allocation #20

Open Querijn opened 1 year ago

Querijn commented 1 year ago

Hey there,

I've encountered a stack overflow crash in render_outline due to the fact that in my setup I cannot allocate 256KB onto the stack. STACK_ALLOC requires at least 256KB of memory (sizeof(Cell) 128 128) which is not available.

On my setup, I've lowered this number to 32 * 32 which fits fine.

coelckers commented 10 months ago

I just ran into this as well. Allocating such a large buffer is a major stability concern - Windows executables normally have only one MB of stack available and this has an extremely high chance of causing a stack overflow.

Querijn commented 10 months ago

This used to be a problem for me for mods: I can't control how the application uses its stack amount when I am not working in that application. At one point I modified the allocator to just be a regular one, and since no response came from this ticket, I assumed the project wasn't alive, and didn't bother reporting my other issues.

tomolt commented 10 months ago

Alright, thank you, I didn't realize how troublesome this issue is at the time. I'll lower the stack allocation limit going forward.

and since no response came from this ticket, I assumed the project wasn't alive, and didn't bother reporting my other issues.

Understandable. I still try to maintain and develop libschrift, but I struggle to allocate much time to it these days.

godmar commented 2 months ago

A comment on the STACK_ALLOC macro. It will always allocate stack space of thresh, even if the needed amount is larger and the actual storage comes from the heap via calloc. A better option may be to use alloca() if it's ok to rely on its presence.