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