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

Re: [PATCH v3 1/3] sparse-checkout: fix segfault on malformed patterns

From
Derrick Stolee <stolee@gmail.com>
Date
Dec 16, 2021, 14:23 UTC
Message-ID
<55dee0a3-5a55-1af9-74b3-296426458f5c@gmail.com>
In-Reply-To
<xmqqv8zp4mfm.fsf@gitster.g>
On 12/15/2021 3:56 PM, Junio C Hamano wrote:
Show 42 quoted lines
> "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 
>> From: Derrick Stolee <dstolee@microsoft.com>
>>
>> Then core.sparseCheckoutCone is enabled, the sparse-checkout patterns are
>> used to populate two hashsets that accelerate pattern matching. If the user
>> modifies the sparse-checkout file outside of the 'sparse-checkout' builtin,
>> then strange patterns can happen, triggering some error checks.
>>
>> One of these error checks is possible to hit when some special characters
>> exist in a line. A warning message is correctly written to stderr, but then
>> there is additional logic that attempts to remove the line from the hashset
>> and free the data.
> 
> Makes sense.
> 
>> This leads to a segfault in the 'git sparse-checkout
>> list' command because it iterates over the contents of the hashset, which is
>> now invalid.
> 
> Understandable.
> 
>> The fix here is to stop trying to remove from the hashset. Better to leave
>> bad data in the sparse-checkout matching logic (with a warning) than to
>> segfault.
> 
> True, as long as it won't make the situation worse by depending on
> that bad data to further damage working tree data or in-repo data
> when damaged working tree data gets committed.  And "list segfaults
> with freed/NULLed data---so leave the bad ones in to print these bad
> ones" feels OK-ish.  
> 
> As long as the user is not transporting the listed output to another
> repository, which may fall into "making the situation worse"
> category by spreading an existing breakage, that is.
> 
> In other words, this may paper over the segfault, and it may be safe
> only for "sparse-checkout list", but is it safe for other operations
> that actually use this bad data to further affect other things in
> the repository?  If not, I wonder if we want to hard die to lock the
> repository down before the issue is fixed to avoid spreading the
> damage?

You're right. I should do what we do elsewhere in this method and disable cone mode pattern matching, reverting to the old matching algorithms. This will clear the hashsets and avoid using them anywhere else.

Show 14 quoted lines
>> +test_expect_success 'malformed cone-mode patterns' '
>> +	git -C repo sparse-checkout init --cone &&
>> +	mkdir -p repo/foo/bar &&
>> +	touch repo/foo/bar/x repo/foo/y &&
>> +	cat >repo/.git/info/sparse-checkout <<-\EOF &&
>> +	/*
>> +	!/*/
>> +	/foo/
>> +	!/foo/*/
>> +	/foo/\*/
>> +	EOF
>> +	cat repo/.git/info/sparse-checkout &&
> 
> Stray debugging output?
Thanks.
>> +	git -C repo sparse-checkout list
> 
> And we are happy as long as the command does not segfault, and we do
> not care what the output is.

And I'll be able to test that the 'list' subcommand changes behavior when cone mode is disabled, in addition to checking stderr for the correct warnings.

Thanks, -Stolee

Previous: Junio C HamanoNext: Derrick Stolee via GitGitGadget
Message 15 of 24 in “sparse-checkout: fix segfault on malformed patterns”
  1. 0/3 sparse-checkout: fix segfault on malformed patternsDerrick Stolee via GitGitGadget, Dec 7, 2021
  2. 1/3 sparse-checkout: fix segfault on malformed patternsDerrick Stolee via GitGitGadget, Dec 7, 2021
  3. Elijah NewrenDec 7, 2021
  4. 2/3 sparse-checkout: fix OOM error with mixed patternsDerrick Stolee via GitGitGadget, Dec 7, 2021
  5. 3/3 sparse-checkout: refuse to add to bad patternsDerrick Stolee via GitGitGadget, Dec 7, 2021
  6. Elijah NewrenDec 7, 2021
  7. Derrick StoleeDec 8, 2021
  8. 0/4 sparse-checkout: fix segfault on malformed patternsDerrick Stolee via GitGitGadget, Dec 10, 2021
  9. 2/4 sparse-checkout: fix OOM error with mixed patternsDerrick Stolee via GitGitGadget, Dec 10, 2021
  10. 1/4 sparse-checkout: fix segfault on malformed patternsDerrick Stolee via GitGitGadget, Dec 10, 2021
  11. 3/4 sparse-checkout: refuse to add to bad patternsDerrick Stolee via GitGitGadget, Dec 10, 2021
  12. 0/3 sparse-checkout: fix segfault on malformed patternsDerrick Stolee via GitGitGadget, Dec 15, 2021
  13. 1/3 sparse-checkout: fix segfault on malformed patternsDerrick Stolee via GitGitGadget, Dec 15, 2021
  14. Junio C HamanoDec 15, 2021
  15. Derrick StoleeDec 16, 2021
  16. 2/3 sparse-checkout: fix OOM error with mixed patternsDerrick Stolee via GitGitGadget, Dec 15, 2021
  17. 3/3 sparse-checkout: refuse to add to bad patternsDerrick Stolee via GitGitGadget, Dec 15, 2021
  18. Junio C HamanoDec 15, 2021
  19. Derrick StoleeDec 16, 2021
  20. Junio C HamanoDec 16, 2021
  21. 0/3 sparse-checkout: fix segfault on malformed patternsDerrick Stolee via GitGitGadget, Dec 16, 2021
  22. 1/3 sparse-checkout: fix segfault on malformed patternsDerrick Stolee via GitGitGadget, Dec 16, 2021
  23. 2/3 sparse-checkout: fix OOM error with mixed patternsDerrick Stolee via GitGitGadget, Dec 16, 2021
  24. 3/3 sparse-checkout: refuse to add to bad patternsDerrick Stolee via GitGitGadget, Dec 16, 2021

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.