ref: 8078f9f84fcfe433019b900b3defc2248517351f
parent: f3ac883d0db6842870cdabd44ed938b92de87d71
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Oct 24 16:27:49 EDT 2025
gefs: fix undercount in reserved space computation when counting the space we needed to reserve in a pivot node, we could undercount by up to 8 bytes; this would only affect us when inserting a maximally sized entry into a node, but could cause crashes.
--- a/sys/src/cmd/gefs/tree.c
+++ b/sys/src/cmd/gefs/tree.c
@@ -308,10 +308,14 @@
/*
* We need to guarantee there's room for one message
* at all times, so that splits along the whole path
- * have somewhere to go as they propagate up.
+ * have somewhere to go as they propagate up. For
+ * each key-ptr pair we have 8 bytes of overhead,
+ * so remember to account for that: 2 bytes of fill,
+ * 2 bytes of offset table, and 2 bytes of length
+ * for both key and value.
*/
bassert(b, b->type == Tpivot);
- return 2*(b->nval+1) + b->valsz + reserve*Kpmax > Pivspc;
+ return 2*(b->nval+1) + b->valsz + reserve*(8+Keymax+Ptrsz) > Pivspc;
}
static void
--
⑨