sciapp / gr

GR framework: a graphics library for visualisation applications
Other
329 stars 54 forks source link

Reasons why text length is limited to 131 bytes (either latin1 or utf8) ? #150

Closed bpedersen2 closed 2 years ago

bpedersen2 commented 2 years ago

gks_text sets a hard limit of 131 bytes for the passed string, is there any real reason behind this (gks.c, line 1172 in current master)?

It got introduced by the following commit (that adds hires-colormap support):

https://github.com/sciapp/gr/commit/b1a23239a2bb1cd5c2ab1b7cc17f903acba0ed20

bpedersen2 commented 2 years ago

Link to file: https://github.com/sciapp/gr/blob/08c185a6ee3fc0ceaebb9b92017def13131bff22/lib/gks/gks.c#L1172

What also looks supsicous there is that for the non-ft code path all encodings are converted to utf8 (with stack-allocated buffers) , while for freetype only latin1 is converted and for this conversion a malloced buffer is used.

bpedersen2 commented 2 years ago

A further look at the downstream impl. (e.g. in the pdf plugin) seems to indicate that the max length accepted there is BUFSIZ-1:

https://github.com/sciapp/gr/blob/08c185a6ee3fc0ceaebb9b92017def13131bff22/lib/gks/pdf.c#L1277-L1290

On modern archictectures BUFSIZ (in stdio.h) is typically 8192 bytes. So probably gks_text should use BUFSIZ as well.

bpedersen2 commented 2 years ago

fixed by 254f0432059f20dbfea669573df2307bf1de8b77