From e243c4c91b79ee385a3715dd1e2cb428d91318f2 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Fri, 25 Nov 2022 15:48:05 +0100 Subject: [PATCH] fix(c/array): null-terminate strings in text array loading --- psycopg_c/psycopg_c/types/array.pyx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/psycopg_c/psycopg_c/types/array.pyx b/psycopg_c/psycopg_c/types/array.pyx index b42d76035..9019d0736 100644 --- a/psycopg_c/psycopg_c/types/array.pyx +++ b/psycopg_c/psycopg_c/types/array.pyx @@ -142,7 +142,7 @@ cdef object parse_token( return load(b) else: - unesc = PyMem_Malloc(length - num_escapes) + unesc = PyMem_Malloc(length - num_escapes + 1) src = start tgt = unesc while src < end: @@ -152,6 +152,8 @@ cdef object parse_token( src += 1 tgt += 1 + tgt[0] = b'\x00' + try: if cloader is not None: return cloader.cload(unesc, length - num_escapes) -- 2.47.2