Commit Graph

108 Commits

Author SHA1 Message Date
161dbaaeb1 rpmio: Fix lzopen_internal mode parsing when 'Tn' is used
When there is number after "T" (suggested number of threads or "0" for
getncpus), lzopen_internal() mode parser would skip one byte, and when
it's at the end of the string it would then parse undesired garbage from
the memory, making intermittent compression failures.

Fixes: c23872d71 ("Add support for multithreaded xz compression")
Fixes-upstream: 7740d1098.
Upstream-PR: https://github.com/rpm-software-management/rpm/pull/1478
2021-01-16 03:16:55 +03:00
ef8e18f471 rpmio: Make xzdio errors more informative
Mode flags could change from what is specified in defines and errors
could happen before any other descriptive messages would appear, but
it's useful to know some additional info about xz compression to debug
multi-threading memory failures.

Reviewed-by: Arseny Maslennikov <arseny@altlinux.org>
2021-01-16 03:16:55 +03:00
56e441c403 rpmio+pack: Update rpmio_flags 'T' with actual threads used
Useful information for debugging liblzma memory issues.

Reviewed-by: Arseny Maslennikov <arseny@altlinux.org>
Reviewed-by: Dmitry V. Levin <ldv@altlinux.org>
2021-01-16 03:16:55 +03:00
cae4cfe66f rpmio: Fix formatting of liblzma error messages
Add forgotten new lines.

Fixes: c254b0d63 ("add rpmlog(RPMLOG_ERR, ...) for liblzma return codes")
2021-01-16 01:57:20 +03:00
58313570f4 rpmio: Workaround another liblzma memory allocation failure on armh
Liblzma is non-robust on memory allocation problems - while it works
well on 64-bit architectures with plenty of RAM, it's problematic on
32-bit architectures when multi-threading is used.

Try another workaround: instead of just guessing the best delta, move
half of the current (512MiB) delta into 'guard malloc' allocation test
of what LZMA encoder memusage would return.

This is definitely hackish (and vulnerable to toctou), but it's that
much we could do without significantly reworking stream_encoder_mt.

Error message:

  Wrote: /usr/src/RPM/RPMS/armh/libmozjs78-tools-78.0.1-alt2.armh.rpm (w5.lzdio)
  error: lzwrite: lzma error 5
  error: lzclose: lzma error 11
  error: create archive failed on file /usr/src/tmp/libmozjs78-buildroot/usr/lib/debug/usr/lib/libmozjs-78.so.debug: cpio: write failed - Bad file descriptor

Amends: f5fcb8f43 ("Lower memory limit on 32-bit arches for xz compression, again")
Amends: afe660558 ("Lower memory limit on 32-bit systems for xz compression")
Amends: 0b18c0498 ("prevent exceeding 32 bit memory limitations with multithreaded xz compression")
Reviewed-by: Dmitry V. Levin <ldv@altlinux.org>
2021-01-16 01:57:02 +03:00
9726c71d1e rpmio: Include rpmmacro.h to fix compilation warning
rpmio.c: In function 'get_compression_threads':
rpmio.c:2114:12: warning: implicit declaration of function 'rpmExpandNumeric' [-Wimplicit-function-declaration]
 2114 |  threads = rpmExpandNumeric("%{getncpus}");
      |            ^~~~~~~~~~~~~~~~

Reported-by: Dmitry V. Levin <ldv@altlinux.org>
2020-12-18 06:26:31 +03:00
f5fcb8f43d rpmio: Lower memory limit on 32-bit arches for xz compression, again
For armh 256 MiB delta is not enough for `w7T.xzdio`.

Fixes:

  [armh] error: lzwrite: lzma error 5
  [armh] error: lzclose: lzma error 11
  [armh] error: create archive failed on file /usr/src/tmp/llvm11.0-buildroot/usr/lib/debug/.build-id/61/30f51d2a9f8b999e986a2f6c027c1266ba2cf9: cpio: write failed - Bad file descriptor

Reviewed-by: Dmitry V. Levin <ldv@altlinux.org>
2020-12-18 03:45:15 +03:00
afe6605589 rpmio: Lower memory limit on 32-bit systems for xz compression
For some systems 128 MiB delta is not enough for `w7T.xzdio`. Found by
experiment that 256 MiB is enough.

Fixes:

  error: create archive failed on file /usr/src/in/source/FlightGear-data-2020.1.2.tar: cpio: write failed - Bad file descriptor
2020-12-13 02:35:37 +03:00
e3d73c95d5 rpmio: Make liblzma errors more verbose
LZMA error codes lost in the depths of IO callbacks. But they could be
informative to user, especially LZMA_MEM_ERROR (5).
2020-12-13 02:35:30 +03:00
0b18c0498e prevent exceeding 32 bit memory limitations with multithreaded xz compression
Based on commit a60f36a55 by Per Øyvind Karlsen. Original commit message:

  As 32 bit build suffers under the limitation of 32 bit address space,
  regardless of it's environment would be ie. 64 bit and not have this
  constration, rpm must make sure not to exceed this memory limitation.
  When using multithreaded xz compression, the number of threads used will
  increase the memory usage, making it necessary to check the memory
  required with the number of threads to be used.

  Number of compression threads will therefore be kept reduced untill
  amount of memory required won't exceed this limitation.

  For 32 bit binaries running under 64 bit host environment, where less
  available memory will be reserved for kernel, easing memory constraints,
  determination of this will be done by a combination of checking host
  arch as well as whether 32 bit personality flag is set, thereby still
  allow a sligthly greater memory usage for such cases to avoid
  imposing unnecessatry limitations under such environments.

Changes from the original commit:

- Do not call uname(2).
- Limits are increased.
- Do not call lzma_memlimit_set().
- No message about thread limitation.

Reviewed-by: Dmitry V. Levin <ldv@altlinux.org>
2020-12-10 19:15:42 +03:00
Martin Liska
7ebe00643c Add get_compression_threads and refactor code.
Merged-by: Vitaly Chikunov <vt@altlinux.org>

Removed 4 thread limitation for 32-bit systems.
2020-12-08 22:48:19 +03:00
Panu Matilainen
e3bd69c7df Add a built-in macro for fetching number of CPUs, affinity aware and all
There's an increasing number of placing wanting to know the number of
CPU's for parallel processing, and increasingly these things are running
in containers and such where the total host CPU count is not meaningful.

Merged-by: Vitaly Chikunov <vt@altlinux.org>
2020-12-08 22:47:59 +03:00
Florian Festi
0263f6ebbd Only use multi thread support with liblzma >= 5.2.0
Merged-by: Vitaly Chikunov <vt@altlinux.org>
2020-12-08 22:47:50 +03:00
Per Øyvind Karlsen
c23872d713 Add support for multithreaded xz compression
Merged-by: Vitaly Chikunov <vt@altlinux.org>
2020-12-08 22:47:50 +03:00
Per Øyvind Karlsen
222d4ff7fc add support for setting xz memlimit
Merged-by: Vitaly Chikunov <vt@altlinux.org>
2020-12-08 22:47:50 +03:00
Per Øyvind Karlsen
c254b0d63f add rpmlog(RPMLOG_ERR, ...) for liblzma return codes 2020-12-08 22:47:50 +03:00
90d5486688 Check for cookie_io_functions_t provided by stdio.h
Do not check for libio.h, it's not included anyway.
Check for cookie_io_functions_t and conditionalize
on HAVE_COOKIE_IO_FUNCTIONS_T instead.
2019-11-24 11:58:18 +00:00
fdd98a7997 Replace all uses of _IO_off64_t with off64_t
Mechanically substitute _IO_off64_t with off64_t using
$ git grep -Fwl _IO_off64_t |xargs -r sed -i s/_IO_off64_t/off64_t/g

This follows glibc-2.28~574 and fixes build with glibc >= 2.28.
2019-11-24 11:58:18 +00:00
Gleb Fotengauer-Malinovskiy
e9c71b57f4 macro.c: force GNU getopt(3) to reinitialize it's internal data structure
getopt(3) holds pointers to previous argument vector in case you want to
continue or restart parsing.
In grabArgs function argument vector is on the stack, so you are lucky
if this memory is not reused for something else between subsequent calls
to the function.  If you are not lucky, getopt(3) will read new
arbitrary value from the stack and return error.
2019-01-31 22:17:45 +03:00
5e8afe3990 Introduce xasprintf
As asprintf() tends to be used without proper error checking,
introduce xasprintf() that does the necessary error checking itself.
2019-01-10 23:20:03 +00:00
Alexey Tourbin
72ad101add 4.0.4-alt113
- Implemented limited support for large files: a 2GB+ file can now be packaged,
  but the total size of uncompressed cpio payload is capped at 4 GB.
- Automatically downgrade LZMA compression levels 7-9 -> 6 on small payloads.
2018-06-26 13:03:42 +03:00
Alexey Tourbin
e854592c75 rpmio.c: updated lzma compression set-up 2018-06-26 12:42:44 +03:00
Alexey Tourbin
a1a075caa2 rpmio: fixed Fwrite() truncated return value
This is the reason why files >= 2G could not be added to cpio, even on
64-bit architectures.  Fwrite was called with a buffer >= 2G, but the
return value was truncated to int (this narrowing conversion is probably
undefined behavior already; what happens next, though, is that after
casting to size_t it assumes a very big numeric value of >= 2^64-2^32).
So rpmbuild was failing with an unrelated errno, "cpio: write failed -
Bad file descriptor".

There are other reasons why this still won't work on 32-bit architectures.
For one, rpmbuild mmaps a file before feeding it to cpio, and 32-bit
architectures have a very limited ability, if any, to mmap 2G+ files.
2018-06-26 12:42:44 +03:00
Gleb Fotengauer-Malinovskiy
62acbd59d6 macro.c: increase maximal macro depth 2018-05-24 16:19:11 +03:00
96a5445b98 Drop bzdio support
There is no use in supporting bzip2 compressed payloads in rpmbuild nowadays.
2017-11-20 01:42:20 +00:00
9515fd6545 rpmio: fix potential buffer overflow in Fdopen
In file included from /usr/include/string.h:648:0,
                 from ../system.h:76,
                 from rpmio.c:6:
In function 'strncat',
    inlined from 'Fdopen' at rpmio.c:3473:5:
/usr/include/bits/string3.h:158:10: warning: call to __builtin___strncat_chk might overflow destination buffer
   return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest));
2017-01-17 16:16:28 +03:00
e8c780c2b0 Disable build and install of unpackaged files
These are no longer packaged anyway, so no need to bother.
2017-01-14 13:42:53 +00:00
4ab56b3647 rpmio: fix potential buffer overflow in Fdopen
In file included from /usr/include/string.h:648:0,
                 from ../system.h:76,
                 from rpmio.c:6:
In function 'strncat',
    inlined from 'Fdopen' at rpmio.c:3473:5:
/usr/include/bits/string3.h:158:10: warning: call to __builtin___strncat_chk might overflow destination buffer
   return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest));
2017-01-14 13:42:53 +00:00
Gleb Fotengauer-Malinovskiy
91210177c1 Make rpm2cpio exit code accurate for large packages
Grab the uncompressed payload size from header and compare number of
bytes copied to that for exit code.  Previously, truncated payloads could
have returned with success.  This also fixes the exit code for large
payloads.
2015-11-18 20:52:46 +03:00
4efd5e5f44 Fix some harmless compilation warnings 2014-02-15 22:44:35 +00:00
4134fc39ac Fix automake warnings
Makefile.am:13: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
build/Makefile.am:5: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
lib/Makefile.am:5: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
python/Makefile.am:7: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
rpmdb/Makefile.am:5: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
rpmio/Makefile.am:9: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
tools/Makefile.am:5: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
2014-02-15 22:19:47 +00:00
3f575cf2bc rpmio/macro.c (doShellEscape): fix an off-by-one error in stripping trailing newlines
Reported by Alexey Tourbin.
2013-02-07 14:25:10 +00:00
120ce7358f Add %_tmpdir builtin macro 2012-12-22 16:52:35 +00:00
0f27ba59eb Add %getenv builtin macro 2012-12-22 16:20:47 +00:00
a470a11bac parseSpec: enhance line buffer overflow diagnostics 2012-03-19 18:18:03 +00:00
Alexey Tourbin
05eb59911d macro.c: fixed macroTable corruption in freeArgs 2011-01-06 05:52:17 +03:00
Alexey Tourbin
6370ecd629 macro.c: replaced repeated bsearch+qsort with BSEARCH, 10x faster startup
"rpmquery rpm" callgrind annotations, previous commit:
86,825,432  PROGRAM TOTALS
33,090,616  ???:0x0000000000033080'2
25,635,193  ???:strcmp
11,530,816  ???:compareMacroName
 7,241,913  ???:memcpy
 2,008,600  ???:0x0000000000033080
 1,734,274  ???:sortMacroTable
   774,941  ???:doDefine
   642,062  ???:0x00000000000714c0
   308,897  ???:0x000000000002a7b0
   308,137  ???:do_lookup_x
   259,615  ???:0x0000000000070c50
   245,388  ???:poptReadConfigFile

"rpmquery rpm" callgrind annotations, this commit:
6,249,372  PROGRAM TOTALS
774,941  ???:doDefine
531,291  ???:addMacro
523,434  ???:0x00000000000714c0
388,985  ???:strcmp
308,897  ???:0x000000000002a7b0
308,098  ???:do_lookup_x
245,388  ???:poptReadConfigFile

"rpmquery rpm" repeated 100 times (user time), previous commit:
3.78s

"rpmquery rpm" repeated 100 times (user time), this commit:
0.40s
2011-01-06 04:04:18 +03:00
Alexey Tourbin
f332ec8636 bsearch.h: initial revision 2011-01-06 03:30:42 +03:00
Alexey Tourbin
4d5831af27 strcasecmp.c: enhanced with table lookup 2011-01-06 03:22:55 +03:00
Kirill A. Shutemov
0ed9eed845 Migrate to new libbeecrypt
Let's try to use recent libbeectypt in our World Best RPM.

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2010-08-12 20:41:06 +00:00
Alexey Tourbin
1ccf0dd03c 4.0.4-alt95.M41.28
- rpmio, rpmbuild: Added support for .xz/.lzma compressed sources and patches.
- Removed old scripts in /usr/lib/rpm.
2009-09-29 16:20:33 +04:00
Alexey Tourbin
6795a36bb1 great removal 2009-09-29 15:29:52 +04:00
Alexey Tourbin
19e6de9d5e added support for .xz/.lzma compressed sources and patches
This also fixes some bugs:
- %uncompress macro never worked;
- %patch -s -b .orig never worked.
2009-09-29 14:18:01 +04:00
Alexey Tourbin
9c4c10a89e 4.0.4-alt95.M41.26
- rpmio: Tweak lzma preset options for better compression.
2009-09-26 02:52:55 +04:00
Alexey Tourbin
147801d6a6 rpmio.c: tweak lzma preset options for better compression 2009-09-26 02:47:34 +04:00
Alexey Tourbin
776a15f6b8 4.0.4-alt95.M41.25
- rpmio: Updated lzma compression routines for xz-5.0 API.
- Packaged /usr/bin/rpm2cpio.static.
2009-09-24 12:46:31 +04:00
Alexey Tourbin
0cded3969f rpmio.c: updated lzdio for xz-5.0 API, added xzdio 2009-09-24 12:30:07 +04:00
4ca252696d Merge branch 'altlinux-4.0' into altlinux-4.1 2009-07-13 23:04:30 +00:00
7e293aed59 rpmio/macro.c (doShellEscape): Fix potential buffer underflow (ALT#11921) 2009-07-13 23:01:04 +00:00
Alexey Tourbin
82d6fbdfe6 4.0.4-alt95.M41.8
- fixed crash in previous release (Dmitry V. Levin)
2008-11-13 07:12:42 +03:00