Skip to content

Commit 709af40

Browse files
KarthikNayakgitster
authored andcommitted
reftable: prevent 'update_index' changes after header write
The function `reftable_writer_set_limits()` allows updating the 'min_update_index' and 'max_update_index' of a reftable writer. These values are written to both the writer's header and footer. Since the header is written during the first block write, any subsequent changes to the update index would create a mismatch between the header and footer values. The footer would contain the newer values while the header retained the original ones. To fix this bug, we now prevent callers from updating these values after the header has been written. Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 44aa262 commit 709af40

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

reftable/writer.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ int reftable_writer_new(struct reftable_writer **out,
182182
void reftable_writer_set_limits(struct reftable_writer *w, uint64_t min,
183183
uint64_t max)
184184
{
185+
/*
186+
* The limits shouldn't be modified post writing the first block, else
187+
* it would cause a mismatch between the header and the footer.
188+
*/
189+
if (w->next)
190+
BUG("update index modified after writing first block");
191+
185192
w->min_update_index = min;
186193
w->max_update_index = max;
187194
}

0 commit comments

Comments
 (0)