commit 83345ba0f563c1b9f11c6898872c634f6f366aed Author: overweight <5324761+overweight@user.noreply.gitee.com> Date: Mon Sep 30 11:20:34 2019 -0400 Package init diff --git a/0014-liblzma-Avoid-memcpy-NULL-foo-0-because-it-is-undefi.patch b/0014-liblzma-Avoid-memcpy-NULL-foo-0-because-it-is-undefi.patch new file mode 100644 index 0000000..cd3aaf6 --- /dev/null +++ b/0014-liblzma-Avoid-memcpy-NULL-foo-0-because-it-is-undefi.patch @@ -0,0 +1,101 @@ +From 2a22de439ec63da1927b640eda309296a1e8dce5 Mon Sep 17 00:00:00 2001 +From: Lasse Collin +Date: Mon, 13 May 2019 20:05:17 +0300 +Subject: [PATCH 14/14] liblzma: Avoid memcpy(NULL, foo, 0) because it is + undefined behavior. + +I should have always known this but I didn't. Here is an example +as a reminder to myself: + + int mycopy(void *dest, void *src, size_t n) + { + memcpy(dest, src, n); + return dest == NULL; + } + +In the example, a compiler may assume that dest != NULL because +passing NULL to memcpy() would be undefined behavior. Testing +with GCC 8.2.1, mycopy(NULL, NULL, 0) returns 1 with -O0 and -O1. +With -O2 the return value is 0 because the compiler infers that +dest cannot be NULL because it was already used with memcpy() +and thus the test for NULL gets optimized out. + +In liblzma, if a null-pointer was passed to memcpy(), there were +no checks for NULL *after* the memcpy() call, so I cautiously +suspect that it shouldn't have caused bad behavior in practice, +but it's hard to be sure, and the problematic cases had to be +fixed anyway. + +Thanks to Jeffrey Walton. +--- + src/liblzma/common/common.c | 6 +++++- + src/liblzma/lz/lz_decoder.c | 12 +++++++++--- + src/liblzma/simple/simple_coder.c | 10 +++++++++- + 3 files changed, 23 insertions(+), 5 deletions(-) + +diff --git a/src/liblzma/common/common.c b/src/liblzma/common/common.c +index 1399b92..18453ae 100644 +--- a/src/liblzma/common/common.c ++++ b/src/liblzma/common/common.c +@@ -99,7 +99,11 @@ lzma_bufcpy(const uint8_t *restrict in, size_t *restrict in_pos, + const size_t out_avail = out_size - *out_pos; + const size_t copy_size = my_min(in_avail, out_avail); + +- memcpy(out + *out_pos, in + *in_pos, copy_size); ++ // Call memcpy() only if there is something to copy. If there is ++ // nothing to copy, in or out might be NULL and then the memcpy() ++ // call would trigger undefined behavior. ++ if (copy_size > 0) ++ memcpy(out + *out_pos, in + *in_pos, copy_size); + + *in_pos += copy_size; + *out_pos += copy_size; +diff --git a/src/liblzma/lz/lz_decoder.c b/src/liblzma/lz/lz_decoder.c +index bb21d0d..6c9024e 100644 +--- a/src/liblzma/lz/lz_decoder.c ++++ b/src/liblzma/lz/lz_decoder.c +@@ -91,11 +91,17 @@ decode_buffer(lzma_coder *coder, + in, in_pos, in_size); + + // Copy the decoded data from the dictionary to the out[] +- // buffer. ++ // buffer. Do it conditionally because out can be NULL ++ // (in which case copy_size is always 0). Calling memcpy() ++ // with a null-pointer is undefined even if the third ++ // argument is 0. + const size_t copy_size = coder->dict.pos - dict_start; + assert(copy_size <= out_size - *out_pos); +- memcpy(out + *out_pos, coder->dict.buf + dict_start, +- copy_size); ++ ++ if (copy_size > 0) ++ memcpy(out + *out_pos, coder->dict.buf + dict_start, ++ copy_size); ++ + *out_pos += copy_size; + + // Reset the dictionary if so requested by coder->lz.code(). +diff --git a/src/liblzma/simple/simple_coder.c b/src/liblzma/simple/simple_coder.c +index 13ebabc..4f499be 100644 +--- a/src/liblzma/simple/simple_coder.c ++++ b/src/liblzma/simple/simple_coder.c +@@ -118,7 +118,15 @@ simple_code(void *coder_ptr, const lzma_allocator *allocator, + // coder->pos and coder->size yet. This way the coder can be + // restarted if the next filter in the chain returns e.g. + // LZMA_MEM_ERROR. +- memcpy(out + *out_pos, coder->buffer + coder->pos, buf_avail); ++ // ++ // Do the memcpy() conditionally because out can be NULL ++ // (in which case buf_avail is always 0). Calling memcpy() ++ // with a null-pointer is undefined even if the third ++ // argument is 0. ++ if (buf_avail > 0) ++ memcpy(out + *out_pos, coder->buffer + coder->pos, ++ buf_avail); ++ + *out_pos += buf_avail; + + // Copy/Encode/Decode more data to out[]. +-- +1.8.3.1 + diff --git a/colorxzgrep.csh b/colorxzgrep.csh new file mode 100644 index 0000000..a3964dc --- /dev/null +++ b/colorxzgrep.csh @@ -0,0 +1,5 @@ +/usr/libexec/grepconf.sh -c +if ( $status == 1 ) exit +alias xzgrep 'xzgrep --color=auto' +alias xzfgrep 'xzfgrep --color=auto' +alias xzegrep 'xzegrep --color=auto' diff --git a/colorxzgrep.sh b/colorxzgrep.sh new file mode 100644 index 0000000..4a91d70 --- /dev/null +++ b/colorxzgrep.sh @@ -0,0 +1,4 @@ +/usr/libexec/grepconf.sh -c || return +alias xzgrep='xzgrep --color=auto' 2>/dev/null +alias xzegrep='xzegrep --color=auto' 2>/dev/null +alias xzfgrep='xzfgrep --color=auto' 2>/dev/null diff --git a/xz-5.2.4.tar.xz b/xz-5.2.4.tar.xz new file mode 100644 index 0000000..9db0680 Binary files /dev/null and b/xz-5.2.4.tar.xz differ diff --git a/xz.spec b/xz.spec new file mode 100644 index 0000000..6c9285b --- /dev/null +++ b/xz.spec @@ -0,0 +1,100 @@ +%global profiledir %{_sysconfdir}/profile.d + +Name: xz +Version: 5.2.4 +Release: 4 +Summary: A free general-purpose data compreession software with LZMA2 algorithm +License: Public Domain, LGPLv2.1 and GPLv2+ +URL: http://tukaani.org/xz +Source0: http://tukaani.org/%{name}/%{name}-%{version}.tar.xz + +#Source1 and Source2 get from fedora +Source1: colorxzgrep.sh +Source2: colorxzgrep.csh + +Patch6000: 0014-liblzma-Avoid-memcpy-NULL-foo-0-because-it-is-undefi.patch + +BuildRequires: perl-interpreter + +Requires: %{name} = %{version}-%{release} +Requires: grep >= 2.20-5 +Provides: xz-libs +Obsoletes: xz-libs +Obsoletes: %{name}-compat-libs < %{version}-%{release} + +%description +XZ Utils is free general-purpose data compression software with a high compression ratio. +XZ Utils were written for POSIX-like systems, but also work on some not-so-POSIX systems. XZ Utils are the successor to LZMA Utils. + +The core of the XZ Utils compression code is based on LZMA SDK, but it has been modified quite a lot to be suitable for XZ Utils. +The primary compression algorithm is currently LZMA2, which is used inside the .xz container format. With typical files, XZ Utils create 30% smaller output than gzip and 15% smaller output than bzip2. + +%package devel +Summary: Libraries & headers for xz +Requires: %{name} = %{version}-%{release} +Provides: lzma = %{version} +Provides: xz-static xz-lzma-compat +Obsoletes: lzma < %{version} +Obsoletes: xz-static xz-lzma-compat + +%description devel +This package mainly includes the following contents: static library, +the header file, example, tests use case, other development and use of content. + +%package help +Summary: Help documentation related to xz +BuildArch: noarch + +%description help +This package includes help documentation and manuals related to xz. + +%prep +%autosetup -n %{name}-%{version} -p1 + +%build +%configure +sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool +sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool +%make_build + +%install +%make_install + +mkdir -p %{buildroot}%{profiledir} +install -p -m 644 %{SOURCE1} %{buildroot}%{profiledir} +install -p -m 644 %{SOURCE2} %{buildroot}%{profiledir} + +%find_lang %name + +%check +LD_LIBRARY_PATH=$PWD/src/liblzma/.libs make check + +%files -f %{name}.lang +%defattr(-,root,root) +%doc %{_pkgdocdir} +%license %{_pkgdocdir}/COPYING* +%{_bindir}/*xz* +%{_bindir}/*lz* + +%{_libdir}/lib*.so.5* +%{profiledir}/* +%exclude %_pkgdocdir/examples* +%exclude %{_libdir}/*.la + +%files devel +%dir %{_includedir}/lzma +%doc %_pkgdocdir/examples* +%{_includedir}/lzma/*.h +%{_includedir}/lzma.h + +%{_libdir}/pkgconfig/liblzma.pc +%{_libdir}/liblzma.a +%{_libdir}/*.so + +%files help +%{_mandir}/man1/*lz* +%{_mandir}/man1/*xz* + +%changelog +* Mon Sep 2 2019 dongjian - 5.2.4-4 +- Rebuild the xz and fix description