Commit Graph

38 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
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
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
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
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
Alexey Tourbin
147801d6a6 rpmio.c: tweak lzma preset options for better compression 2009-09-26 02:47:34 +04:00
Alexey Tourbin
0cded3969f rpmio.c: updated lzdio for xz-5.0 API, added xzdio 2009-09-24 12:30:07 +04:00
Alexey Tourbin
52b2499aff rpmio.c: implemented cpio hints for rsyncable_gzwrite() 2008-05-30 22:23:16 +04:00
Alexey Tourbin
8d5e355e06 rpmio.c: deal with partial rsyncable_gzwrite() return 2008-05-30 20:09:17 +04:00
Alexey Tourbin
f7b5ee1e80 rpmio.c: implemented rscynable_gzwrite() 2008-05-30 20:08:14 +04:00
Alexey Tourbin
c761902bcb rpmio.c: introduced rpmGZFILE wrapper for gzdio 2008-05-30 20:05:08 +04:00
Panu Matilainen
86679b599f Plug a memleak in lzclose() 2008-05-24 13:48:14 +04:00
Alexey Tourbin
9814453966 backported LZMA payload compression from SuSE 2008-05-24 13:47:41 +04:00
8787ee5d55 Fixed "type qualifiers ignored on function return type" issue. 2006-05-15 02:48:59 +04:00
906d5c74b2 fixed gzclose error handling 2003-05-06 15:09:48 +00:00
6cc64fa4ea updated code to snapshot 2002-06-15 of 4_0 branch 2002-08-03 16:35:14 +00:00
dee952c2f8 sync with rpm4 branch: include local headers 2002-03-25 22:02:39 +00:00
82a4763c66 Initial revision 2002-03-25 20:16:26 +00:00