From 0d78fcefd602510c859b7433810df0c2a0ceee8e Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sun, 20 Aug 2023 01:41:35 -0500 Subject: [PATCH] Added assertions on inline size to btree inline code This was missed when moving to use lfsr_data_t more. This is interesting conflict between implicit truncation in lfsr_data_read and strict assertions that inlined btree don't lose data. Found in the btree tests when, you guessed it, inlined btrees lost data. An alternative route would be to make btrees uninline when faced with an entry too big to inlined. This may be valuable future work, but probably depends on the file implementation to know if such a feature is useful. --- lfs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lfs.c b/lfs.c index 702bf69a..6ba203ba 100644 --- a/lfs.c +++ b/lfs.c @@ -3543,6 +3543,7 @@ static lfs_ssize_t lfsr_btree_todisk(lfs_t *lfs, const lfsr_rbyd_t *btree, static int lfsr_data_readbtreeinlined(lfs_t *lfs, lfsr_data_t *data, lfsr_tag_t tag, lfs_size_t weight, lfsr_btree_t *btree) { + LFS_ASSERT(lfsr_data_size(data) <= LFSR_BTREE_INLINESIZE); // mark as inlined btree->u.i.weight = lfsr_btree_setinlined(weight); btree->u.i.tag = tag; @@ -3794,6 +3795,8 @@ static int lfsr_btree_commit(lfs_t *lfs, lfsr_btree_t *btree, // update our inlined tag, make sure to strip wide/grow bits if (lfsr_tag_suptype(lfsr_tag_key(attrs[i].tag)) == LFSR_TAG_STRUCT) { + LFS_ASSERT(lfsr_data_size(&attrs[i].data) + <= LFSR_BTREE_INLINESIZE); btree->u.i.tag = lfsr_tag_key(attrs[i].tag); lfsr_data_t data_ = attrs[i].data;