Git development
 help / color / mirror / Atom feed
From: "Torsten Bögershausen" <tboegi@web.de>
To: Ihar Hrachyshka <ihar.hrachyshka@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] precompose_utf8: use a flex array for d_name
Date: Fri, 3 Jul 2026 07:08:00 +0200	[thread overview]
Message-ID: <20260703050800.GA29216@tb-raspi4> (raw)
In-Reply-To: <20260703023554.36577-1-ihar.hrachyshka@gmail.com>

On Thu, Jul 02, 2026 at 10:35:54PM -0400, Ihar Hrachyshka wrote:
> On macOS, git status may abort while reading a directory entry
> whose UTF-8 name grows past NAME_MAX bytes:
> 
>   __chk_fail_overflow
>   __strlcpy_chk
>   precompose_utf8_readdir
>   read_directory_recursive
>   wt_status_collect
>   cmd_status
> 
> The precompose wrapper already reallocates dirent_prec_psx for
> long names, but d_name is declared as char[NAME_MAX + 1]. A
> fortified libc can still see that declared object size and reject a
> larger strlcpy bound, even though the allocation was grown.
> 
> Make d_name a FLEX_ARRAY and size allocations from offsetof(). That
> matches the actual object layout with the dynamic allocation, so the
> fortified copy sees a destination whose size can grow with max_name_len.
> 
> Add a regression test that creates a 261-byte non-ASCII basename and
> runs status with core.precomposeunicode enabled.
> 
> Signed-off-by: Ihar Hrachyshka <ihar.hrachyshka@gmail.com>

Nice, thanks for the patch.
One minor nit/question:
Do we need a
test_have_prereq PERL
in t/t3910 ?

[]
> diff --git a/t/t3910-mac-os-precompose.sh b/t/t3910-mac-os-precompose.sh
> index 6d5918c..fda4a76 100755
> --- a/t/t3910-mac-os-precompose.sh
> +++ b/t/t3910-mac-os-precompose.sh
> @@ -207,6 +207,21 @@ test_expect_success "Add long precomposed filename" '
>  	git commit -m "Long filename"
>  '
>  
> +test_expect_success "status with long non-ASCII filename" '
> +	test_when_finished "rm -rf long-utf8-status" &&
> +	git init long-utf8-status &&
> +	(
> +		cd long-utf8-status &&
> +		test "$(git config --bool core.precomposeunicode)" = true &&
> +		long_utf8_name=$(
> +			perl -e "print q(a) x 249, qq(\342\200\224) x 3, q(.md)"
> +		) &&
> +		test "$(printf "%s" "$long_utf8_name" | wc -c | tr -d " ")" = 261 &&
> +		printf "content\n" >"$long_utf8_name" &&
> +		git status --porcelain=v1 >actual
> +	)
> +'
> +
>  test_expect_failure 'handle existing decomposed filenames' '
>  	echo content >"verbatim.$Adiarnfd" &&
>  	git -c core.precomposeunicode=false add "verbatim.$Adiarnfd" &&
> 

  reply	other threads:[~2026-07-03  5:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-03  2:35 [PATCH] precompose_utf8: use a flex array for d_name Ihar Hrachyshka
2026-07-03  5:08 ` Torsten Bögershausen [this message]
2026-07-03  8:39   ` Junio C Hamano
2026-07-03  8:40 ` Patrick Steinhardt
2026-07-03 20:20   ` Ihar Hrachyshka
2026-07-04 23:37 ` [PATCH v2] " Ihar Hrachyshka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260703050800.GA29216@tb-raspi4 \
    --to=tboegi@web.de \
    --cc=git@vger.kernel.org \
    --cc=ihar.hrachyshka@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox