From b74bde5cc421bd935d9c01b0a18d405f42782627 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Wed, 29 Nov 2023 12:01:17 -0800 Subject: [PATCH] nostrdb/search: fix infinite loop when parsing some notes Our word parser gets stuck on some notes with utf8 chars. Make sure we are always advancing so we don't get stuck. Signed-off-by: William Casarin --- nostrdb/nostrdb.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nostrdb/nostrdb.c b/nostrdb/nostrdb.c index bec05dde..7545ceb0 100644 --- a/nostrdb/nostrdb.c +++ b/nostrdb/nostrdb.c @@ -2218,6 +2218,7 @@ static inline int consume_until_boundary(struct cursor *cur) { // TODO: We should work towards // handling all UTF-8 characters. //printf("Invalid UTF-8 code point: %x\n", c); + return 0; } } } @@ -2305,6 +2306,14 @@ static int ndb_parse_words(struct cursor *cur, void *ctx, ndb_word_parser_fn fn) if (word_len == 0 && cur->p >= cur->end) break; + if (word_len == 0) { + if (!cursor_skip(cur, 1)) + break; + continue; + } + + //ndb_debug("writing word index '%.*s'\n", word_len, word); + if (!fn(ctx, word, word_len, words)) continue;