From b9d8b1dbf364589f1c88f245ffda9fd269bd92cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=E2=80=99Aquino?= Date: Fri, 11 Jul 2025 16:47:40 -0700 Subject: [PATCH] Fix blocks_size calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously two addresses from different memory regions were being subtracted, which will lead to the incorrect number. This commit improves the calculation. Changelog-None Signed-off-by: Daniel D’Aquino --- nostrdb/src/content_parser.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nostrdb/src/content_parser.c b/nostrdb/src/content_parser.c index ee2621cc..40db04f4 100644 --- a/nostrdb/src/content_parser.c +++ b/nostrdb/src/content_parser.c @@ -594,7 +594,8 @@ int ndb_parse_content(unsigned char *buf, int buf_size, return 0; } - parser.blocks->blocks_size = parser.buffer.p - blocks_start; + parser.blocks->blocks_size = parser.buffer.p - (parser.buffer.start + sizeof(struct ndb_blocks)); + assert(parser.blocks->blocks_size < ((2<<18) + 1)); // // pad to 8-byte alignment @@ -606,4 +607,3 @@ int ndb_parse_content(unsigned char *buf, int buf_size, return 1; } -