From 98c8d60c4f3ea7781c525a48e5971dcda25aaa9e Mon Sep 17 00:00:00 2001 From: zyppe <210hcl@gmail.com> Date: Wed, 28 Feb 2024 21:08:54 +0800 Subject: [PATCH] Initialize for xz --- .gitignore | 1 + .xz.metadata | 1 + baselibs.conf | 4 + bsc1198062.patch | 93 +++++++++++++ xz-5.2.3.tar.gz.sig | Bin 0 -> 565 bytes xz.changes | 330 ++++++++++++++++++++++++++++++++++++++++++++ xz.keyring | 56 ++++++++ xz.spec | 195 ++++++++++++++++++++++++++ xznew | 177 ++++++++++++++++++++++++ xznew.1 | 39 ++++++ 10 files changed, 896 insertions(+) create mode 100644 .gitignore create mode 100644 .xz.metadata create mode 100644 baselibs.conf create mode 100644 bsc1198062.patch create mode 100644 xz-5.2.3.tar.gz.sig create mode 100644 xz.changes create mode 100644 xz.keyring create mode 100644 xz.spec create mode 100644 xznew create mode 100644 xznew.1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..34258a9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +xz-5.2.3.tar.gz diff --git a/.xz.metadata b/.xz.metadata new file mode 100644 index 0000000..8550190 --- /dev/null +++ b/.xz.metadata @@ -0,0 +1 @@ +09d4ea86b3849a3ca76d736725e88676736bdacc649849655de49e8b359390fc xz-5.2.3.tar.gz diff --git a/baselibs.conf b/baselibs.conf new file mode 100644 index 0000000..1cab236 --- /dev/null +++ b/baselibs.conf @@ -0,0 +1,4 @@ +liblzma5 +xz-devel + requires -xz- + requires "liblzma5- = " diff --git a/bsc1198062.patch b/bsc1198062.patch new file mode 100644 index 0000000..ebde6c3 --- /dev/null +++ b/bsc1198062.patch @@ -0,0 +1,93 @@ +From 69d1b3fc29677af8ade8dc15dba83f0589cb63d6 Mon Sep 17 00:00:00 2001 +From: Lasse Collin +Date: Tue, 29 Mar 2022 19:19:12 +0300 +Subject: [PATCH] xzgrep: Fix escaping of malicious filenames (ZDI-CAN-16587). + +Malicious filenames can make xzgrep to write to arbitrary files +or (with a GNU sed extension) lead to arbitrary code execution. + +xzgrep from XZ Utils versions up to and including 5.2.5 are +affected. 5.3.1alpha and 5.3.2alpha are affected as well. +This patch works for all of them. + +This bug was inherited from gzip's zgrep. gzip 1.12 includes +a fix for zgrep. + +The issue with the old sed script is that with multiple newlines, +the N-command will read the second line of input, then the +s-commands will be skipped because it's not the end of the +file yet, then a new sed cycle starts and the pattern space +is printed and emptied. So only the last line or two get escaped. + +One way to fix this would be to read all lines into the pattern +space first. However, the included fix is even simpler: All lines +except the last line get a backslash appended at the end. To ensure +that shell command substitution doesn't eat a possible trailing +newline, a colon is appended to the filename before escaping. +The colon is later used to separate the filename from the grep +output so it is fine to add it here instead of a few lines later. + +The old code also wasn't POSIX compliant as it used \n in the +replacement section of the s-command. Using \ is the +POSIX compatible method. + +LC_ALL=C was added to the two critical sed commands. POSIX sed +manual recommends it when using sed to manipulate pathnames +because in other locales invalid multibyte sequences might +cause issues with some sed implementations. In case of GNU sed, +these particular sed scripts wouldn't have such problems but some +other scripts could have, see: + + info '(sed)Locale Considerations' + +This vulnerability was discovered by: +cleemy desu wayo working with Trend Micro Zero Day Initiative + +Thanks to Jim Meyering and Paul Eggert discussing the different +ways to fix this and for coordinating the patch release schedule +with gzip. +--- + src/scripts/xzgrep.in | 20 ++++++++++++-------- + 1 file changed, 12 insertions(+), 8 deletions(-) + +diff --git a/src/scripts/xzgrep.in b/src/scripts/xzgrep.in +index b180936..e5186ba 100644 +--- a/src/scripts/xzgrep.in ++++ b/src/scripts/xzgrep.in +@@ -180,22 +180,26 @@ for i; do + { test $# -eq 1 || test $no_filename -eq 1; }; then + eval "$grep" + else ++ # Append a colon so that the last character will never be a newline ++ # which would otherwise get lost in shell command substitution. ++ i="$i:" ++ ++ # Escape & \ | and newlines only if such characters are present ++ # (speed optimization). + case $i in + (*' + '* | *'&'* | *'\'* | *'|'*) +- i=$(printf '%s\n' "$i" | +- sed ' +- $!N +- $s/[&\|]/\\&/g +- $s/\n/\\n/g +- ');; ++ i=$(printf '%s\n' "$i" | LC_ALL=C sed 's/[&\|]/\\&/g; $!s/$/\\/');; + esac +- sed_script="s|^|$i:|" ++ ++ # $i already ends with a colon so don't add it here. ++ sed_script="s|^|$i|" + + # Fail if grep or sed fails. + r=$( + exec 4>&1 +- (eval "$grep" 4>&-; echo $? >&4) 3>&- | sed "$sed_script" >&3 4>&- ++ (eval "$grep" 4>&-; echo $? >&4) 3>&- | ++ LC_ALL=C sed "$sed_script" >&3 4>&- + ) || r=2 + exit $r + fi >&3 5>&- +-- +2.35.1 \ No newline at end of file diff --git a/xz-5.2.3.tar.gz.sig b/xz-5.2.3.tar.gz.sig new file mode 100644 index 0000000000000000000000000000000000000000..42325cdd443f1b052076acd3b07e93d36ed6ca84 GIT binary patch literal 565 zcmV-50?Pe~0x|>u0SW*e79j*SkitODQM6|bFs&Ro?sa`>7)Brk0$65IuK)@O5IF92 zeQ6j*AaBPH_}!y5qN{F$P%lNo?5XbLh9}9R_;=uHEk%|kvAEmnVP9*XKnF@q5Kd1j zqpdo5#3xlLKXc@HVUzZaUZG-vTj*wpJYUUfrj#9@5NP%+65KzMXqJLRete~IY-5Ld zVQ~PG{i+H&2jTccpJXT_K;(w(8M7Xy3lc7Kbv90W@bYrbq+<5=GAUdMfV^skZ& zNF9sFoPAsWg9@T`(cM_Oc~#9$W@ci(^}XinVyRx@0d4H#-gXc+sswI)f%T(VjDoG9Jvi<-A*G+4K^`gT9v1_P53NI zd;+NgoX@f}zXuxpS8j|ir#sRrFuS)DnZOz+Fp!_+Q2~h$-GoY<1sus*MiND9cl-IW zUQ>}9;YzLrJYS-wWh0ioGXrklzMvgo`isf@wzKybOo9Eg0Mc*sZ@} +sub 4096R/58ADF744 2010-10-24 + +-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG v2.0.22 (GNU/Linux) + +mQINBEzEOZIBEACxg/IuXERlDB48JBWmF4NxNUuuup1IhJAJyFGFSKh3OGAO2Ard +sNuRLjANsFXA7m7P5eTFcG+Bo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zk6O444qK3RCjLcNmhDC83Vlk0P0zVQARAQABiQIfBBgBAgAJBQJM +xDmSAhsMAAoJEDjudX1pGEYgJosP/A6V89zcX1AHqp5dtKXRa9mCTvtvA+wU6M4b +y/gS7EUos6GH22qe6Y1iEjqTeBgHkmD22TFPjHyfU9nDQOs3s3U+KZE1srjIzvHV +or1anIhl82IQPRxz775If1TT68rdmUadjc9Y6Xe2h8fvIhrkkXpQz/PTLW+gqJjf +xstOT4WUgGpNrYRf2T3A3RhRWLBVakXfzlQg1ZnXp/bQfaMQbrgeuZD5bXF88joo +UY3u1VLaaWwr8TzANBDZGbH3+uzjsuSY/IDspzdo+K0uNAoXSHowAYnlBg8aGubT +PBvJdZ5YE6gdo1++Sk5kJz1S0JNYnzV/Cwh+ne9vba/RHcXPSqEggm9Bv1k43eDD +aSO44Yy7nUhd+X77LOZmsWwRCwUxq05gHCxaUTqPBp8pKysn2/JVI5ik2aDpoLLB +U5gyB5wwreuCXm7qoHGaC2hgBipLgHuBDLHZSOn95TUyi1ZA6/+p1VWHStJXkLHx +ZqIbz46DKa8Uvy81Hn13cqdbTWTSYjjEq4Jd0AMSnewX2nMZ/4dN3xgb3ds361cQ +yVaF7JzyAzUOiyRknw5rGhv5kYGSRLp1SxkBXtp7FajZkMabS2k87ctWb9nQjhJu +Vv6UnpCwiz3gyuipl/GVUWiz4+HXUQgBmTGovm5tJ/9LIwPdw2wbUtF9MJPpCLqT +wOSlnSuT +=u8YC +-----END PGP PUBLIC KEY BLOCK----- diff --git a/xz.spec b/xz.spec new file mode 100644 index 0000000..f2b54b8 --- /dev/null +++ b/xz.spec @@ -0,0 +1,195 @@ +# +# spec file for package xz +# +# Copyright (c) 2022-2023 ZhuningOS +# + + +# avoid bootstrapping problem +%define _binary_payload w9.bzdio +Name: xz +Version: 5.2.3 +Release: 150000.4.7.1 +Summary: A Program for Compressing Files with the Lempel–Ziv–Markov algorithm +License: LGPL-2.1-or-later AND GPL-2.0-or-later AND SUSE-Public-Domain +Group: Productivity/Archiving/Compression +Url: http://tukaani.org/xz/ +Source0: http://tukaani.org/xz/%{name}-%{version}.tar.gz +Source1: http://tukaani.org/xz/%{name}-%{version}.tar.gz.sig +Source2: baselibs.conf +# from http://tukaani.org/misc/lasse_collin_pubkey.txt#/xz.keyring +Source3: xz.keyring +Source4: xznew +Source5: xznew.1 +# PATCH-FIX-SECURITY ZDI-CAN-16587 bsc#1198062 danilo.spinella@suse.com +Patch1: bsc1198062.patch +BuildRequires: pkgconfig +Provides: lzma = %{version} +Obsoletes: lzma < %{version} +BuildRoot: %{_tmppath}/%{name}-%{version}-build +%if 0%{?lang_package:1} +Recommends: %{name}-lang +%endif + +%description +The xz command is a program for compressing files. +* Average compression ratio of LZMA is about 30%% better than that of + gzip, and 15%% better than that of bzip2. +* Decompression speed is only little slower than that of gzip, being + two to five times faster than bzip2. +* In fast mode, compresses faster than bzip2 with a comparable + compression ratio. +* Achieving the best compression ratios takes four to even twelve + times longer than with bzip2. However, this does not affect + decompressing speed. +* Very similar command line interface to what gzip and bzip2 have. + +%lang_package + +%package -n liblzma5 +Summary: Lempel–Ziv–Markov chain algorithm compression library +License: SUSE-Public-Domain +Group: System/Libraries + +%description -n liblzma5 +Library for encoding/decoding LZMA files. + +%package devel +Summary: Development package for the LZMA library +License: SUSE-Public-Domain +Group: Development/Libraries/C and C++ +Requires: liblzma5 = %{version} +Provides: lzma-devel = %{version} +Obsoletes: lzma-devel < %{version} +Provides: lzma-alpha-devel = %{version} +Obsoletes: lzma-alpha-devel < %{version} + +%description devel +This package contains the header files and libraries needed for +compiling programs using the LZMA library. + +%package static-devel +Summary: Static version of LZMA library +License: SUSE-Public-Domain +Group: Development/Libraries/C and C++ +Requires: lzma-devel = %{version} + +%description static-devel +Static library for the LZMA library + +%prep +%setup -q +%patch1 -p1 + +%build +export CFLAGS="%{optflags} -D_REENTRANT -pipe -fPIE" +export LDFLAGS="-Wl,-z,relro,-z,now -pie" +%configure \ + --with-pic \ + --docdir=%{_docdir}/%{name} +%if 0%{?do_profiling} + make %{?_smp_mflags} CFLAGS="${CFLAGS} %{cflags_profile_generate}" + make check %{?_smp_mflags} + make clean + make %{?_smp_mflags} CFLAGS="${CFLAGS} %{cflags_profile_feedback}" +%else + make %{?_smp_mflags} +%endif + +%check +make %{?_smp_mflags} check + +%install +%if 0%{?make_install:1} +%make_install +%else +# Retain this line, with trailing #, to work around an overly eager spec-cleaner +make DESTDIR=%{buildroot} install %{?_smp_mflags} # +%endif +find %{buildroot} -type f -name "*.la" -delete -print +%find_lang %{name} +install -Dpm 0755 %{SOURCE4} %{buildroot}%{_bindir}/xznew +install -Dpm 0644 %{SOURCE5} %{buildroot}%{_mandir}/man1/xznew.1 +rm -vf %{buildroot}%{_docdir}/%{name}/{COPYING,COPYING.GPLv2} + +%post -n liblzma5 -p /sbin/ldconfig +%postun -n liblzma5 -p /sbin/ldconfig + +%if 0%{?lang_package:1} +%files lang -f %{name}.lang +%defattr(-, root, root) +%endif + +%files +%defattr(-, root, root) +%license COPYING COPYING.GPLv2 +%{_docdir}/%{name} +%{_bindir}/lzcat +%{_bindir}/lzcmp +%{_bindir}/lzdiff +%{_bindir}/lzegrep +%{_bindir}/lzfgrep +%{_bindir}/lzgrep +%{_bindir}/lzless +%{_bindir}/lzma +%{_bindir}/lzmadec +%{_bindir}/lzmainfo +%{_bindir}/lzmore +%{_bindir}/unlzma +%{_bindir}/unxz +%{_bindir}/xz +%{_bindir}/xzcat +%{_bindir}/xzcmp +%{_bindir}/xzdec +%{_bindir}/xzdiff +%{_bindir}/xzegrep +%{_bindir}/xzfgrep +%{_bindir}/xzgrep +%{_bindir}/xzless +%{_bindir}/xzmore +%{_bindir}/xznew +%{_mandir}/man1/lzcat.1%{ext_man} +%{_mandir}/man1/lzcmp.1%{ext_man} +%{_mandir}/man1/lzdiff.1%{ext_man} +%{_mandir}/man1/lzegrep.1%{ext_man} +%{_mandir}/man1/lzfgrep.1%{ext_man} +%{_mandir}/man1/lzgrep.1%{ext_man} +%{_mandir}/man1/lzless.1%{ext_man} +%{_mandir}/man1/lzma.1%{ext_man} +%{_mandir}/man1/lzmadec.1%{ext_man} +%{_mandir}/man1/lzmainfo.1%{ext_man} +%{_mandir}/man1/lzmore.1%{ext_man} +%{_mandir}/man1/unlzma.1%{ext_man} +%{_mandir}/man1/unxz.1%{ext_man} +%{_mandir}/man1/xz.1%{ext_man} +%{_mandir}/man1/xzcat.1%{ext_man} +%{_mandir}/man1/xzcmp.1%{ext_man} +%{_mandir}/man1/xzdec.1%{ext_man} +%{_mandir}/man1/xzdiff.1%{ext_man} +%{_mandir}/man1/xzegrep.1%{ext_man} +%{_mandir}/man1/xzfgrep.1%{ext_man} +%{_mandir}/man1/xzgrep.1%{ext_man} +%{_mandir}/man1/xzless.1%{ext_man} +%{_mandir}/man1/xzmore.1%{ext_man} +%{_mandir}/man1/xznew.1%{ext_man} +%if 0%{!?lang_package:1} +%{_datadir}/locale/*/LC_MESSAGES/xz.mo +%endif + +%files -n liblzma5 +%defattr(-, root, root) +%{_libdir}/liblzma.so.5* + +%files devel +%defattr(-, root, root) +%{_includedir}/lzma.h +%dir %{_includedir}/lzma/ +%{_includedir}/lzma/* +%{_libdir}/liblzma.so +%{_libdir}/pkgconfig/liblzma.pc + +%files static-devel +%defattr(-, root, root) +%{_libdir}/liblzma.a + +%changelog diff --git a/xznew b/xznew new file mode 100644 index 0000000..7421e1a --- /dev/null +++ b/xznew @@ -0,0 +1,177 @@ +#!/bin/sh + +# Copyright (C) 2015 Hans-Peter Jansen +# Copyright (C) 1998, 2002, 2004 Free Software Foundation +# Copyright (C) 1993 Jean-loup Gailly + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +PATH="/usr/bin:$PATH"; export PATH +check=0 +pipe=0 +opt= +files= +keep=0 +res=0 +old=0 +new=0 +block=1024 +# block is the disk block size (best guess, need not be exact) + +warn="(does not preserve modes and timestamp)" +tmp=`mktemp -d ${TMPDIR-/tmp}/zfoo.XXXXXX` || { + echo 'cannot create temporary directory' >&2 + exit 1 +} +trap "rm -rf $tmp/" 0 1 2 3 6 13 15 +set -C +echo hi > $tmp/1 +echo hi > $tmp/2 +if test -z "`(${CPMOD-cpmod} $tmp/1 $tmp/2) 2>&1`"; then + cpmod=${CPMOD-cpmod} + warn="" +fi + +if test -z "$cpmod" && ${TOUCH-touch} -r $tmp/1 $tmp/2 2>/dev/null; then + cpmod="${TOUCH-touch}" + cpmodarg="-r" + warn="(does not preserve file modes)" +fi + +# check about xz extension +xz $tmp/1 &> /dev/null +ext=`echo $tmp/1* | sed "s|$tmp/1||"` +rm -rf $tmp/ +trap - 0 1 2 3 6 13 15 +if test -z "$ext"; then + echo xznew: error determining xz extension + exit 1 +fi +if test "$ext" = ".gz"; then + echo xznew: cannot use .gz as xz extension. + exit 1 +fi + +for arg +do + case "$arg" in + -*) opt="$opt $arg"; shift;; + *) break;; + esac +done + +if test $# -eq 0; then + echo "recompress .gz or .tgz files into $ext (xz) files" + echo usage: `echo $0 | sed 's,^.*/,,'` "[-tv9KP]" file.gz... + echo " -t tests the new files before deleting originals" + echo " -v be verbose" + echo " -9 use the slowest compression method (optimal compression)" + echo " -K keep a .gz file when it is smaller than the $ext file" + echo " -P use pipes for the conversion $warn" + exit 1 +fi + +opt=`echo "$opt" | sed -e 's/ //g' -e 's/-//g'` +case "$opt" in + *t*) check=1; opt=`echo "$opt" | sed 's/t//g'` +esac +case "$opt" in + *K*) keep=1; opt=`echo "$opt" | sed 's/K//g'` +esac +case "$opt" in + *P*) pipe=1; opt=`echo "$opt" | sed 's/P//g'` +esac +if test -n "$opt"; then + opt="-$opt" +fi + +for i do + m=`echo $i | sed 's/\.tgz$//'` + if test -f "$m.tgz" ; then + echo "Renaming file *.tgz to *.tar.gz" + mv "$i" "$m.tar.gz" + n=`echo $i | sed 's/\.tgz$/\.tar/'` + else + n=`echo $i | sed 's/\.gz$//'` + fi + if test ! -f "$n.gz" ; then + echo $n.gz not found + res=1; continue + fi + test $keep -eq 1 && old=`wc -c < "$n.gz"` + if test $pipe -eq 1; then + if gzip -d < "$n.gz" | xz $opt > "$n$ext"; then + # Copy file attributes from old file to new one, if possible. + test -n "$cpmod" && $cpmod $cpmodarg "$n.gz" "$n$ext" 2> /dev/null + else + echo error while recompressing $n.gz + res=1; continue + fi + else + if test $check -eq 1; then + if cp -p "$n.gz" "$n.$$" 2> /dev/null || cp "$n.gz" "$n.$$"; then + : + else + echo cannot backup "$n.gz" + res=1; continue + fi + fi + if gzip -d "$n.gz"; then + : + else + test $check -eq 1 && mv "$n.$$" "$n.gz" + echo error while uncompressing $n.gz + res=1; continue + fi + if xz $opt "$n"; then + : + else + if test $check -eq 1; then + mv "$n.$$" "$n.gz" && rm -f "$n" + echo error while recompressing $n + else + # gzip $n (might be dangerous if disk full) + echo error while recompressing $n, left uncompressed + fi + res=1; continue + fi + fi + test $keep -eq 1 && new=`wc -c < "$n$ext"` + if test $keep -eq 1 && test `expr \( $old + $block - 1 \) / $block` -lt \ + `expr \( $new + $block - 1 \) / $block`; then + if test $pipe -eq 1; then + rm -f "$n$ext" + elif test $check -eq 1; then + mv "$n.$$" "$n.gz" && rm -f "$n$ext" + else + xz -d "$n$ext" && gzip "$n" && rm -f "$n$ext" + fi + echo "$n.gz smaller than $n$ext -- unchanged" + + elif test $check -eq 1; then + if xz -t "$n$ext" ; then + rm -f "$n.$$" "$n.gz" + else + test $pipe -eq 0 && mv "$n.$$" "$n.gz" + rm -f "$n$ext" + echo error while testing $n$ext, $n.gz unchanged + res=1; continue + fi + elif test $pipe -eq 1; then + rm -f "$n.gz" + fi +done +exit $res diff --git a/xznew.1 b/xznew.1 new file mode 100644 index 0000000..a341f55 --- /dev/null +++ b/xznew.1 @@ -0,0 +1,39 @@ +.TH XZNEW 1 +.SH NAME +xznew \- recompress .gz or .tgz files to .xz files +.SH SYNOPSIS +.B xznew +[ -ftv9PK] [ name.gz ... ] +.SH DESCRIPTION +.I xznew +recompresses files from .gz (gzip) format to .xz (xz) format. +If you want to recompress a file already in xz format, rename the file +to force a .xz extension then apply xznew. +.SH OPTIONS +.TP +.B \-f +Force recompression from .gz to .xz format even if a .xz file already exists. +.TP +.B \-t +Tests the new files before deleting originals. +.TP +.B \-v +Verbose. Display the name and percentage reduction for each file compressed. +.TP +.B \-9 +Use the slowest compression method (optimal compression). +.TP +.B \-P +Use pipes for the conversion to reduce disk space usage. +.TP +.B \-K +Keep a .gz file when it is smaller than the .xz file +.SH "SEE ALSO" +xz(1), gzip(1) +.SH BUGS +.I xznew +does not maintain the time stamp with the -P option if +.I cpmod(1) +is not available and +.I touch(1) +does not support the -r option.