]> git.ipfire.org Git - thirdparty/git.git/commit
reftable: prevent 'update_index' changes after adding records
authorKarthik Nayak <karthik.188@gmail.com>
Wed, 22 Jan 2025 05:35:49 +0000 (06:35 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 22 Jan 2025 17:51:36 +0000 (09:51 -0800)
commit017bd8923986acd4992fd21f3451fdd15ec6edce
tree12458bf0bb55eaab7322ff7f72e6c7d2471d914a
parente7c1b9f1231e49f5e0c5250ec84c68376619f415
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>
refs/reftable-backend.c
reftable/reftable-error.h
reftable/reftable-writer.h
reftable/stack.c
reftable/writer.c
t/unit-tests/t-reftable-stack.c