Commit Graph
1613 Commits
Author SHA1 Message Date
Michael Stahl 58c31ded02 tdf#159519 comphelper,package: do not store document without SHA256
The problem is that on Windows 7 the password-encrypted documents are
stored unencrypted, without any error message.

This is due to defensive programming in
OStorageHelper::CreatePackageEncryptionData(), which happily continues
if creating the SHA256 hash fails, which is the one required for storing
anything newer than ODF 1.1.

Also, the poorly named ZipPackage::GetEncryptionKey() should check for
consistency, the expectation is that either there's no encryption key
(empty sequence), or the expected one is in the sequence.

Creating the SHA256 uses the crypto::NSSInitializer component, which is
in xsec_xmlsec.dll, which is linked to libxmlsec-mscng.dll, which is
linked to Win32 bcrypt.dll, which doesn't have BCryptKeyDerivation on
Windows 7; to reproduce elsewhere, rm instdir/program/libxsec_xmlsec.so

(regression from commit 26bf26272b
 and (due to revert) commit bfd479abf0)

Change-Id: I0b22e20f6d4d0b1a12ed7d99fac7b5243910f9ba
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163708
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2024-02-22 12:37:29 +01: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
Mike Kaganski 747463809e tdf#154587: allow directory entries in ZIP packages
The problem in the bugdoc was the directory entries. These entries
are valid in ZIP packages (even if not common); they may be useful
to e.g. define per-directory permissions (ACLs).

In normal mode, ZipFile reads central directory; there we can read
if the entry has FAT file attributes; and then, if the entry is a
directory. Then it is OK to skip it.

In repair mode, central directory is not used, local file headers
don't contain a "directory" flag. A workaround is used, checking
if there are entries that represent directories of other entries.

Also this change fixes some places that didn't pass the recovery
flag correctly.

Change-Id: I324671841a2c4d0f279b03801d95c8f2eeb99b46
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162888
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2024-02-01 21:07:54 +01:00
Michael Stahl b85c2459ce check that rtl_random_getBytes() was successful
... everywhere it is used to generate material for encryption.

Change-Id: Id3390376bb2f3a5fa1bbfd735850fce886ef7db2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162873
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2024-02-01 13:54:32 +01:00
Mike Kaganski 0fa827dbb2 Drop std::as_const from css::uno::Sequence iterations
Obsoleted by commit 2484de6728 (Remove
non-const Sequence::begin()/end() in internal code, 2021-10-15) and
commit fb3c04bd19 (Drop non-const
Sequence::operator[] in internal code, 2021-11-05).

Change-Id: Idbafef5d34c0d4771cbbf75b9db9712e504164cd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162640
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2024-01-27 12:43:48 +01:00
Caolán McNamara 2362e414ef cid#1546222 COPY_INSTEAD_OF_MOVE
and

cid#1546154 COPY_INSTEAD_OF_MOVE
cid#1546120 COPY_INSTEAD_OF_MOVE
cid#1546115 COPY_INSTEAD_OF_MOVE
cid#1546111 COPY_INSTEAD_OF_MOVE
cid#1546096 COPY_INSTEAD_OF_MOVE
cid#1546016 COPY_INSTEAD_OF_MOVE
cid#1545980 COPY_INSTEAD_OF_MOVE
cid#1545942 COPY_INSTEAD_OF_MOVE
cid#1545902 COPY_INSTEAD_OF_MOVE
cid#1545869 COPY_INSTEAD_OF_MOVE
cid#1545853 COPY_INSTEAD_OF_MOVE
cid#1545769 COPY_INSTEAD_OF_MOVE
cid#1545742 COPY_INSTEAD_OF_MOVE
cid#1545735 COPY_INSTEAD_OF_MOVE
cid#1545689 COPY_INSTEAD_OF_MOVE

Change-Id: If93debe8b00991761cf1876b3fce27b09906749e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161966
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
2024-01-12 15:21:02 +01:00
Michael Stahl f1117fbfcd tdf#105844 package: ODF wholesome encryption: use package version
... to init the Version property.

The problem is that the outer storage loaded from a wholesome ODF
encrypted document doesn't have a Version, because it doesn't (directly)
contain a document and has no "/" file-entry.

Extract the root element's package version attribute and use it.

The Storage API doesn't distinguish much between the package version and
the root document's (i.e. root folder's) version.

Change-Id: I0fd5f999e9adee674d73fc542402512d0e204897
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161897
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2024-01-11 10:50:20 +01:00
Michael Stahl bac43054e2 tdf#105844 package: ManifestImport: handle argon2 attributes in ...
... standard namespace too.

Change-Id: I46804795da2009dfd8bb95b9286933728a132e5b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161785
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2024-01-09 12:28:18 +01:00
Caolán McNamara 69181dd430 ofz#65480: Integer-overflow
Change-Id: Ie771e6e37237907698e4c39eb50cd940500b86ca
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161540
Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
2024-01-02 20:15:00 +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 c6c5166347 tdf#105844 package: increase PBKDF2 iterations for wholesome ODF encryption
The government recommends 600k iterations.

Change-Id: I8d4137ca8a08c2b3ac0e7724de1c87c2117ec7c4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160768
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2023-12-14 18:32:25 +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 a44a6ab7a5 OFFICE-3708: package: produce correct SHA256 URL
Old versions of LO or other consumers can't read wholesome ODF encrypted
documents anyway, so start using the correct W3C SHA256 URL (see commit
1015d35f23).

Change-Id: Id82ab2c9f605eb2084ff01a26e8186223dd46763
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160764
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2023-12-14 15:41:08 +01:00
Michael Stahl 91f35f22f0 tdf#105844 package: remove root document from manifest ...
... for ODF wholesome encryption.

  4.3  <manifest:file-entry>
  For directories, the manifest file should contain a <manifest:file-entry> element only if a directory contains a document or a sub document.

Because the "encrypted-package" is not a document but a package, we
should probably omit the file-entry for the root document.

ZipPackage::writeTempFile() always generates the root document becuase
it's needed for GPG properties, and ManifestExport filters it out.

A bit tricky to implement, because there isn't a clean distinction
between the package and the root document/storage in the package module,
in particular there's no other place than the root storage to store the
MediaType property.

Change-Id: Id7e72a64e2faa074dce80cd5fefb2fa189e2e3ee
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160717
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2023-12-14 15:38:13 +01:00
Mike Kaganski df6a8667e6 tdf#131575: in repair mode, match names ASCII case-insensitively
It would work for the bugdoc in tdf#131575; but not if the wrong case
is the only problem in the package, because then there would be no
repairment mode active. An alternative could be to use case insensitive
match always, but that looks wrong.

Change-Id: Ie405d37e1dc639482bd2608e4479de5b707a07d4
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160761
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2023-12-14 15:21:35 +01:00
Michael Stahl 77ceeb844a package: GPG encryption: prevent manifest:start-key-generation ...
... completely, as currently it was generated for the first file-entry
due to too late setting of bStoreStartKeyGeneration.

Change-Id: I0cc80169deeea133bff45545fdf20fab6a6bedaf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160716
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2023-12-14 10:36:44 +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 6e3a6ca050 package: move function down
Change-Id: I92742a28cf60a9dfc80001f9ca3c5551fe94472d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160677
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2023-12-13 16:51:28 +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
Michael Stahl 3b347664b2 tdf#105844 package,sfx2: wholesome ODF package wrapping encryption
Redo the ODF encryption by storing an ODF package and wrapping it as a
stream "encrypted-package" in another ODF package, such that there is
only one encrypted stream - this requires only one KDF computation.

* This is only enabled in Experimental mode for now.

* Avoid storing unencrypted data in the pTempFile of SfxMedium, as it
  is usually created in the same directory as the target file, which
  may be on a network share or similar less trusted location.

* SfxMedium::SetEncryptionDataToStorage_Impl() should just set an
  error status if it fails (how can it fail anyway)

* when loading a document, SfxDocPasswordVerifier extracts an encrypted
  inner package (by calling SfxMedium::TryEncryptedInnerPackage())

* SfxMedium::GetStorage() automatically decrypts an encrypted inner
  storage and sets it as the SfxMedium's xStorage

* when storing a document, SfxObjectShell::SaveTo_Impl() creates
  the wrapped storages

* One challenge is to keep the macro/scripting signature working; this
  can only be put in the inner storage, whereas the document signature
  should continue to be on the outer storage; also it must use a Zip
  storage, to see the "META-INF" directory.  This needs a new
  SfxMedium::GetScriptingStorageToSign_Impl() and changes in
  SfxMedium::SignContents_Impl().

Change-Id: Ibfee36ce3a9cd030f2aa2ce1484b6d001cba2389
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160401
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2023-12-07 09:28:38 +01:00
Michael Stahl f6536f4db6 some cosmetic improvements, better warnings
Change-Id: I05a7eeb74088c278aab94519c7f53b0482e38058
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160400
Tested-by: Jenkins
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
2023-12-07 09:28:08 +01:00
Mike Kaganski 86c682273d tdf#96401: allow to detect a broken ZIP package
In deep detection, first check if it's a broken ZIP package. If it is,
set the RepairPackage media descriptor property to true.

Pass the RepairPackage value to the OOXML filter detection.

Change-Id: Ic958283f3cce92ac29ce93ac330cc9e409e3eb78
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159976
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2023-11-26 21:04:30 +01:00
Julien Nabet 06e4696233 c++20: use std::erase(_if) instead of std::remove(_if)+erase (part 6)
Change-Id: Ic073d7444e968e90068aa60847bc9211167f6278
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159626
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
2023-11-18 18:38:56 +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
Stephan Bergmann 6e4d3c3476 Extended loplugin:ostr: Automatic rewrite O[U]StringLiteral: package
Change-Id: I5d70d9291a64139bc2dc60c63173fef862a00f2c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158207
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2023-10-20 07:06:58 +02:00
Noel Grandin 77e13931fd incorrect usage of erase..remove idion
since
    commit c95221f151
    Author: Julien Nabet <serval2412@yahoo.fr>
    Date:   Mon Oct 9 21:19:43 2017 +0200
    Replace list by vector InputStreamsList_Impl (package)

Change-Id: Icd35f74863e68315c7fa580a1009743cc957192a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156184
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2023-08-28 12:59:32 +02:00
Noel Grandin 0193b284e8 new loplugin:constexprliteral
OUStringLiteral should be declared constexpr, to enforce
that it is initialised at compile-time and not runtime.

This seems to make a different at least on Visual Studio

Change-Id: I1698f5fa22ddb480347c2f4d444530c2e0e88d92
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153499
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2023-06-26 13:12:31 +02:00
Mike Kaganski 89a25bcda3 Use getXWeak in package
Change-Id: I838b7c0e45a2a701d400fb7189c5396ed4525a70
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150860
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
2023-06-18 09:25:38 +02:00
Noel Grandin 009b889616 do not throw DisposedException when inside a dispose() method
There is no need to do this, as the documentation of
css.lang.XComponent::dispose at

    udkapi/com/sun/star/lang/XComponent.idl

states:

    After this method has been called, the object should
    behave as passive as possible, thus it should ignore all calls

Otherwise, the effect of throwing here is mostly to disturb the flow of
logic in caller code, preventing other parts of teardown from proceeding
smoothly.

Change-Id: I30e6d1b35f85b727debf4405a995fdc0a4fccde6
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152450
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2023-05-31 18:37:34 +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
Caolán McNamara e7c30e6c1e Resolves: tdf#155005 use of uninitialised value
==2515797== Conditional jump or move depends on uninitialised value(s)
==2515797==    at 0x33FAB399: ZipFile::recover() (ZipFile.cxx:1090)
==2515797==    by 0x33FA4D32: ZipFile::ZipFile(rtl::Reference<comphelper::RefCountedMutex>, com::sun::star::uno::Reference<com::sun::star::io::XInputStream> const&, com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext>, bool, bool) (ZipFile.cxx:111)
==2515797==    by 0x33FEF134: void std::_Construct<ZipFile, rtl::Reference<comphelper::RefCountedMutex>&, com::sun::star::uno::Reference<com::sun::star::io::XInputStream>&, com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&, bool, bool&>(ZipFile*, rtl::Reference<comphelper::RefCountedMutex>&, com::sun::star::uno::Reference<com::sun::star::io::XInputStream>&, com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&, bool&&, bool&) (stl_construct.h:119)
==2515797==    by 0x33FED528: void std::_Optional_payload_base<ZipFile>::_M_construct<rtl::Reference<comphelper::RefCountedMutex>&, com::sun::star::uno::Reference<com::sun::star::io::XInputStream>&, com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&, bool, bool&>(rtl::Reference<comphelper::RefCountedMutex>&, com::sun::star::uno::Reference<com::sun::star::io::XInputStream>&, com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&, bool&&, bool&) (optional:278)
==2515797==    by 0x33FEB73B: void std::_Optional_base_impl<ZipFile, std::_Optional_base<ZipFile, false, false> >::_M_construct<rtl::Reference<comphelper::RefCountedMutex>&, com::sun::star::uno::Reference<com::sun::star::io::XInputStream>&, com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&, bool, bool&>(rtl::Reference<comphelper::RefCountedMutex>&, com::sun::star::uno::Reference<com::sun::star::io::XInputStream>&, com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&, bool&&, bool&) (optional:457)
==2515797==    by 0x33FE77DB: std::enable_if<is_constructible_v<ZipFile, rtl::Reference<comphelper::RefCountedMutex>&, com::sun::star::uno::Reference<com::sun::star::io::XInputStream>&, com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&, bool, bool&>, ZipFile&>::type std::optional<ZipFile>::emplace<rtl::Reference<comphelper::RefCountedMutex>&, com::sun::star::uno::Reference<com::sun::star::io::XInputStream>&, com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&, bool, bool&>(rtl::Reference<comphelper::RefCountedMutex>&, com::sun::star::uno::Reference<com::sun::star::io::XInputStream>&, com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&, bool&&, bool&) (optional:918)
==2515797==    by 0x33FD61FD: ZipPackage::initialize(com::sun::star::uno::Sequence<com::sun::star::uno::Any> const&) (ZipPackage.cxx:760)
==2515797==    by 0x64DE1EC: cppuhelper::ServiceManager::Data::Implementation::doCreateInstanceWithArguments(com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&, com::sun::star::uno::Sequence<com::sun::star::uno::Any> const&) (servicemanager.cxx:732)
==2515797==    by 0x64DDF19: cppuhelper::ServiceManager::Data::Implementation::createInstanceWithArguments(com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&, bool, com::sun::star::uno::Sequence<com::sun::star::uno::Any> const&) (servicemanager.cxx:694)
==2515797==    by 0x64E0E8F: cppuhelper::ServiceManager::createInstanceWithArgumentsAndContext(rtl::OUString const&, com::sun::star::uno::Sequence<com::sun::star::uno::Any> const&, com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const&) (servicemanager.cxx:1018)
==2515797==    by 0x34A3B25F: OStorage_Impl::OpenOwnPackage() (xstorage.cxx:435)
==2515797==    by 0x34A3C16C: OStorage_Impl::ReadContents() (xstorage.cxx:541)
==2515797==  Uninitialised value was created by a stack allocation
==2515797==    at 0x33FAB02C: ZipFile::recover() (ZipFile.cxx:1034)

since:

    commit abda72eeac
    Date:   Mon Feb 20 00:32:22 2023 +0100

        tdf#82984 tdf#94915 zip64 support (import + export)

where

- aEntry.nCompressedSize = nCompressedSize;
- aEntry.nSize = nSize;

was removed before the subsequent use of aEntry.nCompressedSize/aEntry.nSize

change things (git show -w for clarity) to check bounds first just for
the range the extra fields might be in and read those, and then follow
up with the original check that the newly discovered
aEntry.nCompressedSize/aEntry.nSize are within the bounds of the overall
file

Change-Id: Iad4ce8297109b06bc5baf77df4f3e86659cbb4cf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150969
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
2023-04-25 15:10:35 +02:00
Caolán McNamara 80805716a4 tdf#155005 fail gracefully on encountering a negative compression value
we are using sal_Int64 for this so a large enough value can be
interpreted as negative here

Change-Id: Id547a24591aca4b6ed7b7955621641a0666b0bd5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150968
Tested-by: Caolán McNamara <caolanm@redhat.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
2023-04-25 15:10:15 +02:00
Caolán McNamara 397e2d5118 ofz#57529 Integer-overflow
Change-Id: I93775299aa340e2e645a04be5d0bc36a9caea103
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149773
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
2023-03-30 22:02:08 +00: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
Caolán McNamara b6d1cb8874 cid#1521901 Pointer to local outside scope
Change-Id: I38e76440606afb65a8c1ce419c446e234a513659
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148550
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
2023-03-09 20:17:15 +00:00
Caolán McNamara 59b0f67675 ofz#56826 Heap-use-after-free
since:

commit abda72eeac
Date:   Mon Feb 20 00:32:22 2023 +0100

    tdf#82984 tdf#94915 zip64 support (import + export)

Change-Id: Iffc1c54b3ccc5464e217d7f94ecc34b57ec1afb1
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148526
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
2023-03-09 10:18:42 +00:00
Andrea Gelmini 5eae429d02 Fix typo
Change-Id: I4c48c988667ffd9221a0e226ab9c35e1e857e9d5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148489
Tested-by: Jenkins
Reviewed-by: Julien Nabet <serval2412@yahoo.fr>
2023-03-09 06:20:54 +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
Caolán McNamara 1ec54b38f1 assert that Mutex exists at ctor time
and drop the never can be hit throw

Change-Id: I74c92f1ff50ef0f3f6f78a53057f121a3665ec3e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148072
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
2023-03-01 19:37:19 +00:00
Caolán McNamara f6633ad610 cid#1521559 pass arg as ref to prove no Dereference before null check
and

cid#1521561 Dereference before null check

and drop pointless null check

Change-Id: I2e99733eb5f1861bb02f6d8ec7a44ace4ded16cd
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148070
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
2023-03-01 19:37:05 +00:00
Noel Grandin 4e0db1771a flatten OWriteStream
no need to use pimpl pattern here

Change-Id: Iebc412aaad83c2f1fc149cc320729ce25030cbc3
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147949
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2023-02-28 11:48:50 +00:00
Noel Grandin 69794d012f no need to allocate OTypeCollection separately in OStorage
it is only one pointer big

Change-Id: I4af56814be106026515aee6c09caa14e0f3eb09a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147948
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2023-02-28 11:48:42 +00:00
Noel Grandin e0e310bd80 no need to allocate OTypeCollection separately in WSInternalData_Impl
it is only one pointer big

Change-Id: I291b1c0aaba2f46aebabefa0341a9e24cf20eeff
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147947
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2023-02-28 10:54:02 +00:00
Noel Grandin cf4e1e0bb8 osl::Mutex->std::mutex in OHierarchyElement_Impl
Change-Id: I458cab160f337019402659b5fb738ba85f73ea1b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147190
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
2023-02-17 07:33:24 +00:00
Gabor Kelemen 259ae22056 Drop 'using namespace ::std' in dirs [e-p]*
Change-Id: Ibe6a2f662f5721c594d28a8e0d7340d0f3cffe95
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147075
Tested-by: Jenkins
Reviewed-by: Gabor Kelemen <kelemeng@ubuntu.com>
2023-02-15 18:39:38 +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