From c09a4eece687c23846b922ec2ec8740859aaa210 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 24 Jun 2025 12:53:12 -0400 Subject: Revert "Do text deserialization in chunks to avoid possible memory issues" (Breaks with unicode text) This reverts commit 389132400b6d3c1f7c767aaf3546d19e93909eb3. --- src/stdlib/text.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/stdlib/text.c b/src/stdlib/text.c index 8b01529d..2107c1df 100644 --- a/src/stdlib/text.c +++ b/src/stdlib/text.c @@ -1617,19 +1617,13 @@ public void Text$serialize(const void *obj, FILE *out, Table_t *pointers, const public void Text$deserialize(FILE *in, void *out, List_t *pointers, const TypeInfo_t *info) { (void)info; - int64_t len = 0; + int64_t len = -1; Int64$deserialize(in, &len, pointers, &Int64$info); - if (len < 0) - fail("Invalid text length during deserialization!"); - Text_t text = EMPTY_TEXT; - while (text.length < len) { - static char chunk[1024] = {}; - size_t chunk_size = MIN(sizeof(chunk), (size_t)(len - text.length)); - if (fread(chunk, sizeof(char), chunk_size, in) != chunk_size) - fail("Not enough data in stream to deserialize"); - text = concat2(text, Text$from_strn(chunk, chunk_size)); - } - *(Text_t*)out = text; + char *buf = GC_MALLOC_ATOMIC((size_t)len+1); + if (fread(buf, sizeof(char), (size_t)len, in) != (size_t)len) + fail("Not enough data in stream to deserialize"); + buf[len+1] = '\0'; + *(Text_t*)out = Text$from_strn(buf, (size_t)len); } public const TypeInfo_t Text$info = { -- cgit v1.2.3