nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

commit 5b6a20c6c0827a864bac29a88bdcc6e35ce7479f
parent 84862c7b71fade3b4a6cd8d4748a5baabeca118b
Author: Daniel D’Aquino <daniel@daquino.me>
Date:   Wed,  4 Jun 2025 20:47:57 -0700

nostrdb: Fix heap buffer overflow

The Address Sanitizer detected a heap buffer overflow during a memcpy operation
in nostrdb.c associated with note parsing.

It was found that not enough memory was being allocated to the buffer to
support all the content parsing.

Allocation size was increased to support the memory needed for the
parsing operations. However, the new number was not carefully calculated
as we will not run into this code path once we switch to the local relay
model.

Changelog-Fixed: Fixed memory error in nostrdb
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Msrc/nostrdb.c | 2+-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/nostrdb.c b/src/nostrdb.c @@ -8152,7 +8152,7 @@ static struct ndb_blocks *ndb_note_to_blocks(struct ndb_note *note) if (content_len >= INT32_MAX) return NULL; - unsigned char *buffer = malloc(content_len); + unsigned char *buffer = malloc(2<<18); // Not carefully calculated, but ok because we will not need this once we switch to the local relay model if (!buffer) return NULL;