reftable: prevent 'update_index' changes after adding records
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 protect against this bug, prevent callers from updating these values after any record is written. To do this, modify the function to return an error whenever the limits are modified after any record adds. Check for record adds within `reftable_writer_set_limits()` by checking the `last_key` and `next` variable. The former is updated after each record added, but is reset at certain points. The latter is set after writing the first block. Modify all callers of the function to anticipate a return type and handle it accordingly. Add a unit test to also ensure the function returns the error as expected. Helped-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
e7c1b9f123
commit
017bd89239
@ -1058,8 +1058,10 @@ static int stack_write_compact(struct reftable_stack *st,
|
||||
|
||||
for (size_t i = first; i <= last; i++)
|
||||
st->stats.bytes += st->readers[i]->size;
|
||||
reftable_writer_set_limits(wr, st->readers[first]->min_update_index,
|
||||
st->readers[last]->max_update_index);
|
||||
err = reftable_writer_set_limits(wr, st->readers[first]->min_update_index,
|
||||
st->readers[last]->max_update_index);
|
||||
if (err < 0)
|
||||
goto done;
|
||||
|
||||
err = reftable_merged_table_new(&mt, st->readers + first, subtabs_len,
|
||||
st->opts.hash_id);
|
||||
|
||||
Reference in New Issue
Block a user