From 4691bb059ffec1b65272434439d254c436d77386 Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 7 Nov 2026 17:04:55 -1000 Subject: Link a file name of stray bytes percent-encoded No test gave a file name invalid UTF-8 or a control byte, which APFS refuses on disk, so the tree is built through the index. --- tests/t0301-security.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'tests') diff --git a/tests/t0301-security.sh b/tests/t0301-security.sh index 4626c2c..229aecb 100755 --- a/tests/t0301-security.sh +++ b/tests/t0301-security.sh @@ -684,4 +684,22 @@ test_expect_success 'robots.txt turns crawlers away from snapshots and blame' ' test_cmp expect rules ' +# A file name may hold any byte but a slash or a NUL, invalid UTF-8 and +# control bytes included, which only reach the tree through the index on a +# filesystem that refuses such names. Escaping is ASCII-based, so they need +# no entity, but a link has to carry them percent-encoded. +test_expect_success 'a file name of stray bytes is linked percent-encoded' ' + mkrepo repos/bytes 1 && + blob=$(git -C repos/bytes rev-parse HEAD:file-1) && + git -C repos/bytes update-index --add --cacheinfo "100644,$blob,$(printf "bad\377name")" && + git -C repos/bytes update-index --add --cacheinfo "100644,$blob,$(printf "ctl\001name")" && + git -C repos/bytes commit -q -m bytes && + cgitrc_repo bytesrc bytes && + cgit_ok bytesrc "url=bytes/tree/" >tmp && + test_grep "href=./bytes/tree/bad%FFname.>" tmp && + test_grep "href=./bytes/tree/ctl%01name.>" tmp && + cgit_ok bytesrc "url=bytes/tree/bad%FFname" >tmp && + test_grep "
blob: $blob " tmp +' + test_done -- cgit 2.12.1