428 Commits
Author SHA1 Message Date
Gabor Kelemen 3fc666e120 Fix some non self contained headers in modules [a-r]*
Change-Id: I844cfcfa2bc31fae0256e0c7b757b6223ac8ac35
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196633
Reviewed-by: Gabor Kelemen <gabor.kelemen@collabora.com>
Tested-by: Jenkins
2026-01-18 00:34:04 +01:00
Caolán McNamara 8788657853 drop some more COVERITY stuff
Change-Id: Ib2ac522e2ae5143fee86cb93f1e779f241129087
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192153
Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
2025-10-10 11:13:00 +02:00
Michael Stahl abfdc11fa4 tdf#167205 package: fix writing Zip64 local headers
This would be reported on reading as an 8-byte gap at the position where
a 32-bit DD for the entry would end.

The problem is that if flag bit 3 is set, and the uncompressed size
exceeds 2^32, writeDataDescriptor() will write 8-byte sizes, but the
Zip64 extension header is missing - the latter should also write 0 even
though the APPNOTE doens't appear to require it.

      4.3.9.2 [...] When extracting, if
      the zip64 extended information extra field is present for
      the file the compressed and uncompressed sizes will be 8
      byte values.

Also make sure that the ZipEntry nSize member actually contains the
uncompressed size, which is somewhat tricky, but is required in
writeLOC() to check if Zip64 is needed.  (Assume that the DEFLATEd size
is never larger than uncompressed, which is true for every XML file).

Change-Id: I611e6ffda12d8e6953e9306dc4a4407be8e725a0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191185
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Michael Stahl <michael.stahl@collabora.com>
2025-09-23 11:42:58 +02:00
Noel Grandin 7e71af5af4 tdf#167936 crash when opening document from UNO pipe
regression from
    commit a6ad198d09
    Author: Noel Grandin <noel.grandin@collabora.co.uk>
    Date:   Sat Aug 17 13:19:54 2024 +0200
    tdf#158556 use more comphelper::ByteReader

Change-Id: I2cc14d0dbb0214dcf54938796eeeebefbd86bd88
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189577
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2025-08-14 13:04:07 +02:00
Noel Grandin 0caf06c8fa remove some dead stuff in package
ever since
    commit b410749d30
    Author: Akshay Kumar Dubey <akshaymani513@gmail.com>
    Date:   Wed Apr 16 02:05:16 2025 +0530
    tdf#137308 - Add zstd build support and decompression classes

Change-Id: Ib67a2ef523ce6596b562633b0da081ba56d3ff6f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185411
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2025-05-16 15:45:41 +02:00
Akshay Kumar Dubey b410749d30 tdf#137308 - Add zstd build support and decompression classes
Integrate build system support for the Zstandard (zstd) library and
implement the corresponding C++ decompression stream classes, enabling
future use of zstd-compressed streams in ZIP packages.

Build System (Part 2a):
- Add `--with-system-zstd=[yes|no|auto]` configure option.
- Implement system library checks (`zstd.h`, `libzstd`) in configure.ac.
- Define rules (`external/zstd/*`) for downloading and building the
  internal zstd static library (decompression components only).
- Set up necessary CFLAGS/LIBS via configure.ac and config_host.mk.in.
- Configure linking via RepositoryExternal.mk (`gb_LinkTarget__use_zstd`).
- Update auxiliary files (download.lst, distro-configs, etc.).

C++ Implementation (Part 2b):
- Implement `InflateZstd` (in `include/package`) and `InflaterBytesZstd`
  (in `package/inc`) inheriting from `Inflater`/`InflaterBytes`.
- Use the zstd streaming API (`ZSTD_decompressStream`) following the
  existing single-call pattern established by the zlib implementation.
- Manage context (`ZSTD_DCtx`) and input buffer (`ZSTD_inBuffer`) state.
- Handle errors, stream completion (`ret == 0`), and input truncation.
- Add new classes to `package/Library_package2.mk` build.

This completes the infrastructure for zstd decompression support.
The next step (Part 2c) involves adding logic to select the
appropriate Inflater based on the ZIP entry's compression method ID.

Change-Id: Ia673f3f19b6a751ba5225394fcf8c3f145c4ae63
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184243
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
2025-05-01 12:18:19 +02:00
Akshay Kumar Dubey 3e1aa5805c tdf#137308 - Part 1: Refactor Inflater classes for extensibility
Refactor ZIP decompression classes (Inflater, InflaterBytes) to support multiple decompression algorithms, enabling future Zstandard
support.

Make Inflater and InflaterBytes abstract base classes defining a common interface. Move the original zlib/Deflate logic into new derived classes InflateZlib and InflaterBytesZlib.

Update usage sites to instantiate the *Zlib variants via unique_ptr to the base class, preserving existing functionality. Move header files to standard locations (include/package, package/inc) and update includes and build files.

This pure refactoring prepares the codebase for adding Zstandard (zstd) decompression. Correct a minor logical bug in the ZipFile::getSizeAndCRC loop condition.

Change-Id: I9be3c02946e29eb2dae09f500eb47d8a4261af22
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183504
Reviewed-by: Devansh Varshney <varshney.devansh614@gmail.com>
Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Tested-by: Jenkins
2025-04-29 09:38:52 +02:00
Gabor Kelemen 109e9d6a61 Remove obsolete fw declarations from package/
found with bin/find-unneeded-includes --fwdecl

Change-Id: I00bb2b3216bbd171bed6b71565876e6f60ccc083
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183895
Tested-by: Jenkins
Reviewed-by: Gabor Kelemen <gabor.kelemen.extern@allotropia.de>
2025-04-27 10:08:57 +02:00
Michael Stahl 91b297730b tdf#166040 package: ZipFile::recover() find DD without PK78 signature
The PK78 signature is optional, and if the sizes in the local file
header are 0 then without the DD the recovery won't do anything useful.

If the latest local file header has the DD bit set in flags, then try to
find the DD before the next thing that has a PK?? signature.

Change-Id: I149a87805f7bcb6216fc909c20ece600ce77956d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183722
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Tested-by: Jenkins
2025-04-04 20:35:45 +02:00
Arnaud VERSINI 83579ee9f1 package : reduce OUString allocation by using u16string_view
Change-Id: I6c52fe7dbf3072132853ad820b5eba58beb6d76c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174149
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Tested-by: Jenkins
2025-03-02 19:28:34 +01:00
Noel Grandin 437aaf54c6 loplugin:unusedmethods
Change-Id: I24666a7746f8920ddf84731f204f3e1a5b9b0c85
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177024
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2024-11-22 20:03:48 +01:00
Noel Grandin 33d4760998 loplugin:passstuffbyref in lotuswordpro..pyuno
Change-Id: I9cd7a98d74b1896951124740b66d873ca41cceae
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176197
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Jenkins
2024-11-07 13:17:27 +01:00
Michael Stahl 9012355a60 tdf#162866 package: fix loading AutoCorrect file with case-insensitive
... duplicates; the directory names of AutoCorrect entries are
user-editable, so this needs to be supported.

AutoCorrect uses an ODF package because the ODF document loading code
requires the ODF document to be in an ODF storage with a MediaType
property.

AutoCorrect writes an empty mimetype file, and if such is present in an
.odt file that is being loaded, existing checks will detect it as
corrupted, so we can use this to check that the file is an AutoCorrect
file and turn off the case-insensitive check.

(regression from commit 4833f13124)

Change-Id: I43887f7dad0c8cbb465b4c0f1c38bcc3244a7675
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173477
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Tested-by: Jenkins
2024-09-17 10:40:29 +02:00
Michael Stahl 6e76e8a210 tdf#162841 package: fix loading AES-GCM encrypted macros from ODF
The problem is that ZipPackageStream::GetEncryptionData() doesn't handle
the checksum correctly; what is required here is *no checksum* but the
check of m_oImportedChecksumAlgorithm results in calling
m_rZipPackage.GetChecksumAlgID() instead, so it ends up in invalid
situation and assert:

  package/source/zippackage/ZipPackageStream.cxx:656: virtual bool ZipPackageStream::saveChild(): Assertion `xEncData->m_nEncAlg != xml::crypto::CipherID::AES_GCM_W3C' failed.

Refactor this so all the imported algorithm identifiers are in a struct
in a std::optional member.

(regression from commit 09f23a3dc5)

Change-Id: I4b705520cd9bc800ce3c8611f8ad01a1e1008929
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173342
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Tested-by: Jenkins
2024-09-16 19:09:44 +02:00
Michael Stahl 15e238757a package: m_nMagicalHackSize appears superfluous
Change-Id: Idc32af25b7835b04b777a2a0767e1982d074f6d4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173322
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2024-09-13 16:46:45 +02:00
Michael Stahl 33d55465d9 tdf#162823 package: fix loss of ODF encrypted basic macros
The problem is that there is a ZipEntry ZipPackageStream::aEntry which
does not necessarily correspond to the values read from the Zip central
directory, because of a call to ZipPackageStream::setSize() in
ZipPackageStream::successfullyWritten() to override nSize and nMethod
for encrypted entries.

This triggers the consistency checks in readLOC(), where this aEntry is
passed.

Refactor things so that ZipPackageStream::aEntry and thus hopefully all
ZipEntry instances correspond to the Zip file's central directory.

For encrypted entries, store the decompressed size (which is read from
manifest.xml) in m_nOwnStreamOrigSize and pass it as a separate
parameter to the ZipFile functions that need it, and ultimately to
XUnbufferedStream, resolving multiple TODO comments.

(regression from commit efae4fc42d)

Change-Id: Ib6ea32595c6027b98da9196a2e2bd0a99b62a983
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173273
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Tested-by: Jenkins
2024-09-13 11:32:38 +02:00
Mike Kaganski 84f6d11780 Use unique_ptr to pass ownership of ZipEntry
Change-Id: I09ffa752d2cd0367579e9384b992215b2d79b251
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172963
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2024-09-07 17:11:48 +02:00
Noel Grandin bf1099e360 tdf#158556 reduce allocations in ZipFile
we can allocate these buffers one caller up in ReadCEN and then re-use
them

Change-Id: I07e98168ee2884286f4a1c281acd86e365416149
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172481
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Jenkins
2024-08-28 07:35:23 +02:00
Noel Grandin 1a47d1e00d tdf#158556 unnecessary temporary OUString in ZipFile
Change-Id: Iea3bf5fa9ba5210eabca521316cfd68b440ec806
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172458
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2024-08-27 17:24:36 +02:00
Noel Grandin a6ad198d09 tdf#158556 use more comphelper::ByteReader
which avoids a ton of temporary uno::Sequence being created

Change-Id: I237bb69395f692bb0272ca0daec05b81af828e01
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171968
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Jenkins
2024-08-27 09:10:04 +02:00
Arnaud VERSINI e099249fd1 Remove now useless include in package
Change-Id: I8085fb69a752e69820113cf3074bf5e4e7c942de
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172020
Reviewed-by: Arnaud Versini <arnaud.versini@pm.me>
Tested-by: Jenkins
2024-08-19 08:31:13 +02:00
Noel Grandin 4f5d694e58 tdf#158556 ByteGrabber does not need a mutex
it is only used from one place, and that place already locks a mutex
around all usage

Change-Id: I85a8d89220bee7806db5457d69cfcf2f11c1734d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171947
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2024-08-16 14:01:07 +02:00
Michael Stahl 32cad89592 package: ZipPackage: add additional check for entries STORED with
... data descriptor; only allow it for encrypted ODF entries, which
requires reading the manifest first.

Change-Id: If36d31a4cb93e7af78f48be3ed899ad9d9bb28f0
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171911
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2024-08-16 10:29:58 +02:00
Michael Stahl ca21cc985d package: ZipFile: check Zip64 end of central directory for consistency
Change-Id: Iae873ec8175922e210398ef8e0f83e148a795c2c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170783
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Tested-by: Jenkins
2024-07-29 12:40:23 +02:00
Caolán McNamara fa10be85d2 cid#1607270 silence Overflowed integer argument
lets see if this works instead.

Change-Id: Ib0a5df7deed2972cfed7c3afbe5c65229c208f26
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171056
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
2024-07-26 11:22:55 +02:00
Michael Stahl 0fb25ce9ff package: don't check case insensitive duplicates for ZIP package
Turns out there's a TexMaths extension that contains files with names
differing only in case.

https://ask.libreoffice.org/t/zipexception-when-installing-an-extension/108256

There isn't a separate ZipPackage mode for OXT so just don't check in
the ZIP mode.

Change-Id: I7680c93f5f24ac566a59b131b36d855bd85100b9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170616
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2024-07-17 14:11:38 +02:00
Michael Stahl efae4fc42d package: add additional consistency checks for local file header
Check it contains same as central directory header, also check data
descriptor if available.  Also check there are no gaps or overlaps.

This causes 3 fuzzer generated test documents to fail to load; adapt
tests.

Change-Id: If5813652f3bd03e90fdf95eb97e1e1523455b2b8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170571
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2024-07-16 15:57:43 +02:00
Michael Stahl 4833f13124 package: ZipFile: don't accept duplicate entries (case insensitive)
This is required for OOXML, but not for ODF.

Unclear if there are use cases for this with ODF, can add some
conditions if it turns out to be a problem.

Change-Id: I3810da5c2273574135d133b4a9bbad98dc97af44
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170223
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2024-07-10 12:08:09 +02:00
Michael Stahl 67dca5a47d package: ZipFile: check Info-ZIP Unicode Path Extra Field
Change-Id: I829eb449e8a0947341f066399be549f56b0f02da
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169882
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2024-07-02 18:44:51 +02:00
Caolán McNamara e5aa87aeeb drop requirement for rtl_random_getBytes to have "Pool" arg
Seeing as since:

commit e9531b792d
Date:   Tue Feb 6 14:39:47 2024 +0100

    sal: rtlRandomPool: require OS random device, abort if not present

    Both rtl_random_createPool() and rtl_random_getBytes() first try to get
    random data from the OS, via /dev/urandom or rand_s() (documented to
    call RtlGenRandom(), see [1]).

we don't use the initial arg to rtl_random_getBytes anymore, drop the
requirement to have one. Then simplify our usages of that, and
addtionally deprecate rtl_random_createPool and rtl_random_destroyPool.

Change-Id: I13dcc067714a8a741a4e8f2bfcf2006373f832c4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167067
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
2024-05-08 11:29:54 +02:00
Mike Kaganski a53f0dc811 Extract Local file header and Data descriptor handling into own functions
Change-Id: I16405f13298934945cc1d5d4a50d403b37c3234e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162912
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2024-02-02 07:27:29 +01:00
Caolán McNamara 6ef28599b2 cid#1545612 COPY_INSTEAD_OF_MOVE
and

cid#1545605 COPY_INSTEAD_OF_MOVE
cid#1545587 COPY_INSTEAD_OF_MOVE

Change-Id: Iafb1d81dbacfefe70fbddd84b29e827dc137ef07
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161077
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
2023-12-20 20:59:04 +01:00
Michael Stahl 2c0f520c03 package: ODF encryption: fix 2 GPG problems
1. ManifestImport should attach KeyInfo to the first file-entry, not to
   a "/" entry which may not exist or may be preceded by another
   file-entry which requires the KeyInfo to decrypt
   (regression from commit 91f35f22f0)

2. manifest:key-size on manifest:key-derivation is unfortunately
   specified to have a default value of 16, but with AES256 the actual
   size is 32, and for GPG the ManifestExport forgot to export it

Change-Id: I05dd2c9e219ba7f20ba33bf0b35d47a9e3df74cc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161072
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2023-12-20 18:42:50 +01:00
Michael Stahl 2f512aaa6c tdf#105844 offapi,package,sfx2: use Argon2 for wholesome ODF encryption
https://www.rfc-editor.org/rfc/rfc9106.html

* add css::xml::crypto::KDFID constant group
* add "KeyDerivationFunction" to setEncryptionAlgorithms sequence
* Argon2 is used by default for wholesome ODF encryption, but
  $LO_ARGON2_DISABLE can be set to use PBKDF2
* extend various structs in package
* use 3 new ODF attributes "loext:argon2-iterations" "loext:argon2-memory"
  "loext:argon2-lanes" to store the arguments
* use this URL for now:
  "urn:org:documentfoundation:names:experimental:office:manifest:argon2id"
* use default arguments according to second recommendation from "7.4.
  Recommendations" of RFC9106; 64 MiB RAM should hopefully not be too
  much even for 32 bit builds

Change-Id: I683118cc5e0706bd6544db6fb909096768ac9920
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161009
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2023-12-20 18:29:36 +01:00
Michael Stahl fb9c58a2f3 tdf#105844 package: check for unexpected zip entries on loading ...
... ODF wholesome encrypted package.

There can only be "mimetype", "encrypted-package", and files in
"META-INF".

Change-Id: I5eb46ba29a1a62e25af09e189e0a075a871c71c4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160718
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2023-12-14 17:59:35 +01:00
Michael Stahl 09f23a3dc5 tdf#105844 package,sfx2: remove checksum infoleak when using AEAD
AEAD provides the verification of the password automatically, by reading
the entire stream the tag at the end will be verified.

The existing attributes manifest:checksum-type/manifest:checksum leak
information about the plain text.

This was mitigated with the addChaffWhenEncryptedStorage() functions
(see commit f57baefbd3) but a better
solution that also works for non-XML streams is to simply omit the
attributes; authenticated encryption provides better verification
without any leak.

* "ChecksumAlgorithm" property can be set to void now to remove the
  checksum
* change a bunch of members in EncryptionData, ZipPackage,
  ZipPackageStream to optional
* change ZipFile::checkValidPassword() to open the stream and return it

Change-Id: Id95288d0c238c4f9940fc5a185df814e8edcbad3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160711
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2023-12-13 22:02:52 +01:00
Michael Stahl f0fda7ad22 tdf#105844 offapi,package,sfx2,xmlsecurity: add AEAD w/ AES GCM
... and use it in the new experimental ODF encryption mode.

https://www.w3.org/TR/xmlenc-core1/#sec-AES-GCM

Unfortunately it turned out that NSS PK11_CipherOp() does not work with
CKM_AES_GCM because it is initialized with "context->multi = PR_FALSE"
in sftk_CryptInit(), so the one-step functions PK11_Encrypt() and
PK11_Decrypt() have to be used.

NSS 3.52 also changed a parameter struct definition - see
https://fedoraproject.org/wiki/Changes/NssGCMParams - which is not a
problem for RHEL or SUSE system NSS since those are rebased, but it
is likely a problem for less well maintained Ubuntu LTS, so use
the old struct definition which evidently still works with NSS 3.94.

NSS 3.52 also added a new PK11_AEADOp() API but it looks like this
doesn't support incremental encryption either.

Change-Id: Ibd4a672db74b65b1218926ba35ff8d2f70444c7e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160505
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2023-12-11 20:46:40 +01:00
Stephan Bergmann bd6fb0cd3e Extended loplugin:ostr: Rewrite some O[U]StringLiteral -> O[U]String
...in include files.  This is a mix of automatic rewriting in include files and
manual fixups (mostly addressing loplugin:redundantfcast) in source files that
include those.

Change-Id: I1f3cc1e67b9cabd2e9d61a4d9e9a01e587ea35cc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158337
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2023-10-23 11:04:42 +02:00
Noel Grandin 8270eb5d56 loplugin:unusedmethods
Change-Id: Ief95f111350808f010539bb733a553007d30a9df
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152006
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2023-05-20 12:55:07 +02:00
Caolán McNamara d41b436058 expose recovering zips for testing
Change-Id: I4709a2fb0bbb0fcc4c7d57dad53c899e7ba79cb4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150971
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
2023-04-25 17:03:40 +02:00
Stephan Bergmann 7cce1141c6 Missing includes (for std::exception_ptr)
Change-Id: If93883ba9feb22e6da2d56af4ebb2f4eafe58de1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149162
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2023-03-20 15:21:08 +00:00
Attila Szűcs abda72eeac tdf#82984 tdf#94915 zip64 support (import + export)
Implemented import + export for "Zip64 Extended Information Extra Field",
(in "Local file header" and "Central directory file header")
and for Data descriptor.
Focused only to be able to handle files with over 4GB uncompressed size,
in the zip archive.
The 64k filecount, and the 4GB compressed size limit is probably still present

Tried to follow pkware .ZIP File Format Specification,
Some cases were not clear to me and/or some zip compressing tool may not
perfectly follow the standard, like 'extra field' should be 28 bytes long,
but its reader now can read shorter (or longer) 'extra field'.

Replaced some 32bit codes with 64bit codes, in stream handling, in deflater.

Tested with an ods file that contained a content.xml that bigger then 4BG+
(import + export + reimport) on windows.
I think 4GB+ files import/export would be too slow fot unittest.
So, for unit test, used the small but zip64 format files,
that was attached to the bugzilla tickets

Note: It helps with Bug 128244 too (1 of the unittest tests it),
but that ods file missing manifest.xml, so LO won't be able to import it.

Change-Id: Idfeb90594388fd34ae719677f5d268ca9a484fb1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147306
Tested-by: Jenkins
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
2023-03-08 14:53:57 +00:00
Noel Grandin a04bf69bcc XUnoTunnel->dynamic_cast in ZipPackageEntry
Change-Id: I0c49ebcb0ed16ab5b90c0cfa1417f002b5dad7b8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145632
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2023-01-17 19:09:51 +00:00
Noel Grandin cb004bdefb XUnoTunnel->dynamic_cast in ZipPackage
Change-Id: I4ecfbb0e90cca7e81556fb27fd552669bed0405c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145631
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2023-01-17 07:49:12 +00:00
Noel Grandin 848f9b2c56 tdf#133767 new service TempFileFastService
to use in places where we know we can use the TempFileFast mechanism.

Speeds up export to EPUB from 43s to 17s on my windows machine.

This is essentially a copy of OTempFileService, but it does not
implement XTempFile (because these temp files have no name on Windows).

Also remove a couple of calls to Flush() (which is not necessary now),
and TellEnd(), which is a little slow on Windows.

Change-Id: Iced300bf8121eae08c7a011d62ec68b93330d84c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141598
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2022-10-21 12:01:05 +02:00
Noel Grandin f6bf58503d use more string_view in package
Change-Id: Ia38b2784222701d669f244523ce9a27c4068c5ab
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140639
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2022-09-27 13:32:26 +02:00
Stephan Bergmann 91ba9654ba Move tools/diagnose_ex.h to comphelper/diagnose_ex.hxx
...so that its TOOLS_WARN_EXCEPTION can be used in
comphelper/source/misc/logging.cxx in a follow-up commit.  (And while at it,
rename from diangose_ex.h to the more appropriate diagnose_ex.hxx.  The
comphelper module is sufficiently low-level for this immediate use case, so use
that at least for now; o3tl might be even more suitable but doesn't have a
Library until now.  Also, for the immediate use case it would have sufficed to
only break DbgGetCaughtException, exceptionToString, TOOLS_WARN_EXCEPTION,
TOOLS_WARN_EXCEPTION_IF, and TOOLS_INFO_EXCEPTION out of
include/tools/diagnose_ex.h into an additional new
include/comphelper/diagnose_ex.hxx, but its probably easier overall to just move
the complete include file as is.)

Change-Id: I9f3222d4ccf1a9ac29d7eb9ba1530d53e2affaee
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138451
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2022-08-18 17:10:19 +02:00
Noel Grandin 74ff1a4355 clang-tidy modernize-pass-by-value in package
Change-Id: Id12d7b38d278c9fb18b30c6d921713a53168b048
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136337
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2022-06-23 18:24:16 +02:00
Stephan Bergmann b4163877e7 Use more appropriate return type for ThreadPool::getPreferredConcurrency
All call sites already effectively asked for an unsigned return type, including:
* The ThreadPool ctor took an nWorkers argument of type sal_Int32, but
  internally stores that as std::size_t mnMaxWorkers.
* ZipOutputStream::reduceScheduledThreadTasksToGivenNumberOrLess apparently
  benefits from an unsigned nThreadTasks parameter, getting rid of various casts
  in its implementation that were necessary to silence signed vs. unsigned
  comparison warnings.

The only drawback is that

  comphelper::ThreadPool::getPreferredConcurrency() * 4

in package/source/zippackage/ZipPackageStream.cxx would now silently wrap around
instead of causing UB on overflow (which could be detected with appropriate
tools).  Ideally, it would use some o3tl::saturating_mul if we had that, so add
a TODO comment for now.

While std::thread::hardware_concurrency returns unsigned, it looked more natural
to go with std::size_t here, as some call sites already used that (see above),
so the implementation of ThreadPool::getPreferredConcurrency is a natural place
to hide clamping std::thread::hardware_concurrency() to std::size_t (in the
unlikely case that std::size_t is of smaller rank than unsigned).

This required addition of o3tl::clamp_to_unsigned in o3tl/safeint.hxx.

Change-Id: I0a04a8b32e63ebfeb39f924c4b38520455a6fb38
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135309
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2022-06-02 17:13:17 +02:00
Noel Grandin 9f958c076a loplugin:passstuffbyref
Change-Id: I336fd329b577b6fa141265d8bc7ce67784bd7306
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133210
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2022-04-20 15:24:34 +02:00