git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] reftable/writer: ensure valid range for log's update_index

From
karthik nayak <karthik.188@gmail.com>
Date
Dec 7, 2024, 09:54 UTC
Message-ID
<CAOLa=ZRYDqhAPMiuAS-HGaC1huiUGgLW3hL_dDNwrFA5c8ewEQ@mail.gmail.com>
In-Reply-To
<xmqqwmgcv23b.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 20 quoted lines
> Karthik Nayak <karthik.188@gmail.com> writes:
>
>> 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.
>
> Interesting.  I am a little curious how this was found.  As long as
> the other parts of the system (i.e. the callers) are not buggy, the
> update pointer will stay within the range, and that is why I do not
> think I can write an end-to-end test to trigger an existing bug that
> would be caught by this "fix".

I was reading the reftable code and noticed it. So mostly luck. Agreed with what you're saying, I'd say this is mostly a 'safeguard'.

Show 5 quoted lines
> Fixing the existing unit tests that
> feed a wrong input and expect some right outcome is good, but would
> it be a good to also have a new unit test that validates that such
> an incorrect precondition for calling is caught and the caller gets
> the expected REFTABLE_API_ERROR as a result, I wonder?

I'm confused, I did add a _new_ test in this patch to do exactly what you're suggesting.

> Being able
> to trigger a condition that is harder to do with the end-to-end test
> is one good thing about having unit test framework, no?
>

Totally, these kind of specific changes are perfect for unit-tests. Plus it was very simple to add one too.

> Will queue.  Thanks.
Thanks!
Karthik
Previous: Junio C HamanoNext: Toon Claes
Message 6 of 7 in “reftable/writer: ensure valid range for log's update_index”
  1. reftable/writer: ensure valid range for log's update_indexKarthik Nayak, Dec 5, 2024
  2. Patrick SteinhardtDec 6, 2024
  3. karthik nayakDec 6, 2024
  4. reftable/writer: ensure valid range for log's update_indexKarthik Nayak, Dec 6, 2024
  5. Junio C HamanoDec 6, 2024
  6. karthik nayakDec 7, 2024
  7. Toon ClaesDec 11, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.