commit b74bde5cc421bd935d9c01b0a18d405f42782627
parent 0e0c53145faa0e40b9e193947858b5ded2469dae
Author: William Casarin <jb55@jb55.com>
Date: Wed, 29 Nov 2023 12:01:17 -0800
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 <jb55@jb55.com>
Diffstat:
1 file changed, 9 insertions(+), 0 deletions(-)
diff --git 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;