diff options
author | Karthik Nayak <karthik.188@gmail.com> | 2024-12-06 14:13:19 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-12-07 00:04:46 +0100 |
commit | 49c6b912e2f4c49784d471f8c9364077c423dbf5 (patch) | |
tree | b2dba4903044d658ee4d19f5bd67293c67ae5202 /reftable | |
parent | The twelfth batch (diff) | |
download | git-49c6b912e2f4c49784d471f8c9364077c423dbf5.tar.xz git-49c6b912e2f4c49784d471f8c9364077c423dbf5.zip |
reftable/writer: ensure valid range for log's update_index
Each reftable addition has an associated update_index. While writing
refs, the update_index is verified to be within the range of the
reftable writer, i.e. `writer.min_update_index <= ref.update_index` and
`writer.max_update_index => ref.update_index`.
The corresponding check for reflogs in `reftable_writer_add_log` is
however missing. Add a similar check, but only check for the upper
limit. This is because reflogs are treated a bit differently than refs.
Each reflog entry in reftable has an associated update_index and we also
allow expiring entries in the middle, which is done by simply writing a
new reflog entry with the same update_index. This means, writing reflog
entries with update_index lesser than the writer's update_index is an
expected scenario.
Add a new unit test to check for the limits and fix some of the existing
tests, which were setting arbitrary values for the update_index by
ensuring they stay within the now checked limits.
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'reftable')
-rw-r--r-- | reftable/writer.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/reftable/writer.c b/reftable/writer.c index fd136794d5..f87086777c 100644 --- a/reftable/writer.c +++ b/reftable/writer.c @@ -412,6 +412,18 @@ int reftable_writer_add_log(struct reftable_writer *w, if (log->value_type == REFTABLE_LOG_DELETION) return reftable_writer_add_log_verbatim(w, log); + /* + * Verify only the upper limit of the update_index. Each reflog entry + * is tied to a specific update_index. Entries in the reflog can be + * replaced by adding a new entry with the same update_index, + * effectively canceling the old one. + * + * Consequently, reflog updates may include update_index values lower + * than the writer's min_update_index. + */ + if (log->update_index > w->max_update_index) + return REFTABLE_API_ERROR; + if (!log->refname) return REFTABLE_API_ERROR; |