commit: 75d1b66dd525f4f24e99200cf7d8fd902e921b40
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sun Jun 8 11:54:37 2025 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Jun 8 13:36:12 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=75d1b66d
ecompress: don't process pathnames containing <newline>
In some instances, ecompress produces and consumes streams consisting of
null-terminated pathnames. In other instances, ecompress produces and
consumes streams consisting of <newline>-terminated pathnames. In
particular, the temporary files comprise <newline>-terminated pathnames.
This requirement is further entrenched by the manner in which the
do_ignore() function makes use of the sort(1) and comm(1) utilities.
In other words, there are two incompatible data models at play. Thus, it
is imperative that the the constraints imposed by the lesser model are
adhered to. The only way to do that is to refuse to process pathnames
that contain the <newline> in any capacity. Impose this necessary
constraint by introducing the changes described herewith.
Have both the do_ignore() and do_queue() functions disregard operands
that contain <newline>. This concerns the composition of the
".ecompress_skip_files" and ".ecompress_had_precompressed" files,
respectively.
Have the do_queue() function invoke find(1) in such a way that any
pathname containing <newline> is disregarded. This concerns the
composition of the ".ecompress_had_precompressed" file.
In all cases where find(1) is charged with locating files whose names
match the "*.ecompress" glob, invoke it in such a way that any pathname
containing <newline> is disregarded.
I would add that, while these changes will almost certainly be invisible
in nature - and will remain largely unappreciated - there can be no
excuse for dodging the issue.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/ecompress | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/bin/ecompress b/bin/ecompress
index d848d18275..a21391d1ed 100755
--- a/bin/ecompress
+++ b/bin/ecompress
@@ -19,7 +19,11 @@ do_ignore() {
: > "${T}/.ecompress_skip_files" || die
for skip; do
- if [[ -d ${ED%/}/${skip#/} ]]; then
+ if [[ ${skip} == *$'\n'* ]]; then
+ # The operand must be disregarded because the temporary
+ # files comprise <newline>-terminated pathnames.
+ continue
+ elif [[ -d ${ED%/}/${skip#/} ]]; then
skip_dirs+=( "${ED%/}/${skip#/}" )
else
rm -f -- "${ED%/}/${skip#/}.ecompress" \
@@ -33,7 +37,7 @@ do_ignore() {
skip=${skip%.ecompress}
printf '%s\n' "${skip#"${D%/}"}" || ! break
done \
- < <(printf '%s\0' "${skip_dirs[@]}" | find0 -name '*.ecompress'
-print0 -delete) \
+ < <(printf '%s\0' "${skip_dirs[@]}" | find0 -name '*.ecompress'
! -path $'*\n*' -print0 -delete) \
>> "${T}/.ecompress_skip_files" || die
# Check whether the invocation of find(1) succeeded.
@@ -57,7 +61,11 @@ do_queue() {
local -A collisions
for path; do
- if [[ -e ${ED%/}/${path#/} ]]; then
+ if [[ ${path} == *$'\n'* ]]; then
+ # The operand must be disregarded because the temporary
+ # files comprise <newline>-terminated pathnames.
+ continue
+ elif [[ -e ${ED%/}/${path#/} ]]; then
paths+=( "${ED%/}/${path#/}" )
fi
done
@@ -67,6 +75,9 @@ do_queue() {
if [[ ${PORTAGE_DOCOMPRESS_SIZE_LIMIT} ]]; then
find_args+=( -size "+${PORTAGE_DOCOMPRESS_SIZE_LIMIT}c"
)
fi
+ # Note that the find(1) command that feeds this loop is made to
+ # ignore pathnames containing <newline>. It must do so because
+ # the temporary files comprise <newline>-terminated pathnames.
while IFS= read -rd '' path; do
# detect the horrible posibility of the ebuild
installing
# colliding compressed and/or uncompressed variants
@@ -92,7 +103,7 @@ do_queue() {
: >> "${path}.ecompress" || die
done \
- < <(printf '%s\0' "${paths[@]}" | find0 "${find_args[@]}"
-print0) \
+ < <(printf '%s\0' "${paths[@]}" | find0 "${find_args[@]}" !
-path $'*\n*' -print0) \
> "${T}"/.ecompress_had_precompressed || die
# Check whether the invocation of find(1) succeeded.
@@ -212,7 +223,7 @@ done
# setup compression stuff
PORTAGE_COMPRESS=${PORTAGE_COMPRESS-bzip2}
if [[ -z ${PORTAGE_COMPRESS} ]]; then
- printf '%s\0' "${ED}" | find0 -name '*.ecompress' -delete
+ printf '%s\0' "${ED}" | find0 -name '*.ecompress' ! -path $'*\n*'
-delete
exit 0
fi
@@ -243,7 +254,7 @@ fi
export PORTAGE_COMPRESS_SUFFIX PORTAGE_COMPRESS_FLAGS PORTAGE_COMPRESS
printf '%s\0' "${ED}" \
-| find0 -name '*.ecompress' -delete -print0 \
+| find0 -name '*.ecompress' ! -path $'*\n*' -delete -print0 \
| ___parallel_xargs -0 "${PORTAGE_BIN_PATH}"/ecompress-file
all_compressed=$(( $? == 0 ))