PG-2116 Truncate query strings at multi-byte character boundaries

Make sure we never create broken encodings in query strings by making
the truncation of query strings multi-byte aware. An alternative would
be to change the rule for truncation to be based on number of
characters, as the documentation claims it is, but I do not think that
would be significantly better. Either works just fine so we just pick
one.

Based on bug report from Ivan Vyazmitinov:

https://github.com/percona/pg_stat_monitor/issues/599
This commit is contained in:
Andreas Karlsson
2025-12-23 17:10:27 +01:00
committed by Andreas Karlsson
parent fef78a8f6f
commit 5526e413c1
3 changed files with 22 additions and 1 deletions

View File

@@ -1983,7 +1983,7 @@ pgsm_store(pgsmEntry *entry)
/* New query, truncate length if necessary. */
if (query_len > pgsm_query_max_len)
query_len = pgsm_query_max_len;
query_len = pg_mbcliplen(query, query_len, pgsm_query_max_len);
/* Save the query text in raw dsa area */
query_dsa_area = get_dsa_area_for_query_text();