shithub: gefs

Download patch

ref: 0568aee47bbfe78e7ab608fda0b667e4508ada0c
parent: dddef538cf344c68dbc40e6b3dd7f39be9821779
author: Ori Bernstein <ori@eigenstate.org>
date: Tue Nov 7 22:10:27 EST 2023

tree: handle truncation edge case with multiple Oclearb messages

--- a/tree.c
+++ b/tree.c
@@ -511,7 +511,16 @@
 			if(m.op != Oinsert)
 				cpkvp(&v, &v, buf, sizeof(buf));
 			while(j < up->hi){
-				if(m.op == Oclearb){
+				/*
+				 * If a file is truncated multiple times,
+				 * we can end up with duplicate Oclearb
+				 * messages in the buffer.
+				 *
+				 * These Oclearb doublings will leave
+				 * v.nv with a length of 0, so we can
+				 * and should skip those
+				 */
+				if(m.op == Oclearb && v.nv != 0){
 					bp = unpackbp(v.v, v.nv);
 					freeblk(t, nil, bp);
 				}