include/sal/types.h | 6 ++ oox/source/crypto/CryptTools.cxx | 11 ++++ sw/qa/extras/uiwriter/uiwriter8.cxx | 40 ++++++++++++++++ sw/source/core/doc/DocumentContentOperationsManager.cxx | 14 ++++- 4 files changed, 68 insertions(+), 3 deletions(-)
New commits: commit 709b0820d86d5e00659949db82837c86ddb9607c Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Feb 21 22:27:37 2024 +0600 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Wed Feb 21 23:03:14 2024 +0600 Implement SAL_WNODEPRECATED_DECLARATIONS_[PUSH/POP] on MSVC Required for --disable-nss build on Windows, which needs the same fix as in commit 71d4abc51b556e147ab53a9a52b15be36fc710a3 (-Werror,-Wdeprecated-declarations (Emscripten), 2024-01-18). Change-Id: I4206cbc0cb80be7ddee1c3f21de50d853828300e diff --git a/include/sal/types.h b/include/sal/types.h index df160d2eef50..c61956f647d7 100644 --- a/include/sal/types.h +++ b/include/sal/types.h @@ -504,6 +504,12 @@ template< typename T1, typename T2 > inline T1 static_int_cast(T2 n) { _Pragma(SAL_STRINGIFY_ARG(GCC diagnostic ignored "-Wdeprecated-declarations")) #define SAL_WNODEPRECATED_DECLARATIONS_POP \ _Pragma(SAL_STRINGIFY_ARG(GCC diagnostic pop)) +#elif defined LIBO_INTERNAL_ONLY && defined _MSC_VER +#define SAL_WNODEPRECATED_DECLARATIONS_PUSH \ + _Pragma(SAL_STRINGIFY_ARG(warning(push))) \ + _Pragma(SAL_STRINGIFY_ARG(warning(disable : 4996))) +#define SAL_WNODEPRECATED_DECLARATIONS_POP \ + _Pragma(SAL_STRINGIFY_ARG(warning(pop))) #else # define SAL_WNODEPRECATED_DECLARATIONS_PUSH # define SAL_WNODEPRECATED_DECLARATIONS_POP commit 0e0f991054d4e8142e209bc8aecfae9af603cd9e Author: Stephan Bergmann <stephan.bergm...@allotropia.de> AuthorDate: Thu Jan 18 13:16:56 2024 +0100 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Wed Feb 21 21:35:39 2024 +0600 -Werror,-Wdeprecated-declarations (Emscripten) > oox/source/crypto/CryptTools.cxx:57:40: error: 'HMAC_CTX_free' is deprecated [-Werror,-Wdeprecated-declarations] > void operator()(HMAC_CTX* p) { HMAC_CTX_free(p); } > ^ > workdir/UnpackedTarball/openssl/include/openssl/hmac.h:35:1: note: 'HMAC_CTX_free' has been explicitly marked deprecated here > OSSL_DEPRECATEDIN_3_0 void HMAC_CTX_free(HMAC_CTX *ctx); > ^ > workdir/UnpackedTarball/openssl/include/openssl/macros.h:182:49: note: expanded from macro 'OSSL_DEPRECATEDIN_3_0' > # define OSSL_DEPRECATEDIN_3_0 OSSL_DEPRECATED(3.0) > ^ > workdir/UnpackedTarball/openssl/include/openssl/macros.h:62:52: note: expanded from macro 'OSSL_DEPRECATED' > # define OSSL_DEPRECATED(since) __attribute__((deprecated)) > ^ > oox/source/crypto/CryptTools.cxx:112:29: error: 'HMAC_CTX_new' is deprecated [-Werror,-Wdeprecated-declarations] > mpHmacContext.reset(HMAC_CTX_new()); > ^ > workdir/UnpackedTarball/openssl/include/openssl/hmac.h:33:1: note: 'HMAC_CTX_new' has been explicitly marked deprecated here > OSSL_DEPRECATEDIN_3_0 HMAC_CTX *HMAC_CTX_new(void); > ^ > workdir/UnpackedTarball/openssl/include/openssl/macros.h:182:49: note: expanded from macro 'OSSL_DEPRECATEDIN_3_0' > # define OSSL_DEPRECATEDIN_3_0 OSSL_DEPRECATED(3.0) > ^ > workdir/UnpackedTarball/openssl/include/openssl/macros.h:62:52: note: expanded from macro 'OSSL_DEPRECATED' > # define OSSL_DEPRECATED(since) __attribute__((deprecated)) > ^ > oox/source/crypto/CryptTools.cxx:125:9: error: 'HMAC_Init_ex' is deprecated [-Werror,-Wdeprecated-declarations] > HMAC_Init_ex(mpHmacContext.get(), rKey.data(), rKey.size(), aEvpMd, nullptr); > ^ > workdir/UnpackedTarball/openssl/include/openssl/hmac.h:43:1: note: 'HMAC_Init_ex' has been explicitly marked deprecated here > OSSL_DEPRECATEDIN_3_0 int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, > ^ > workdir/UnpackedTarball/openssl/include/openssl/macros.h:182:49: note: expanded from macro 'OSSL_DEPRECATEDIN_3_0' > # define OSSL_DEPRECATEDIN_3_0 OSSL_DEPRECATED(3.0) > ^ > workdir/UnpackedTarball/openssl/include/openssl/macros.h:62:52: note: expanded from macro 'OSSL_DEPRECATED' > # define OSSL_DEPRECATED(since) __attribute__((deprecated)) > ^ > oox/source/crypto/CryptTools.cxx:499:12: error: 'HMAC_Update' is deprecated [-Werror,-Wdeprecated-declarations] > return HMAC_Update(mpImpl->mpHmacContext.get(), rInput.data(), nActualInputLength) != 0; > ^ > workdir/UnpackedTarball/openssl/include/openssl/hmac.h:45:1: note: 'HMAC_Update' has been explicitly marked deprecated here > OSSL_DEPRECATEDIN_3_0 int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, > ^ > workdir/UnpackedTarball/openssl/include/openssl/macros.h:182:49: note: expanded from macro 'OSSL_DEPRECATEDIN_3_0' > # define OSSL_DEPRECATEDIN_3_0 OSSL_DEPRECATED(3.0) > ^ > workdir/UnpackedTarball/openssl/include/openssl/macros.h:62:52: note: expanded from macro 'OSSL_DEPRECATED' > # define OSSL_DEPRECATED(since) __attribute__((deprecated)) > ^ > oox/source/crypto/CryptTools.cxx:512:12: error: 'HMAC_Final' is deprecated [-Werror,-Wdeprecated-declarations] > (void) HMAC_Final(mpImpl->mpHmacContext.get(), aHash.data(), &nSizeWritten); > ^ > workdir/UnpackedTarball/openssl/include/openssl/hmac.h:47:1: note: 'HMAC_Final' has been explicitly marked deprecated here > OSSL_DEPRECATEDIN_3_0 int HMAC_Final(HMAC_CTX *ctx, unsigned char *md, > ^ > workdir/UnpackedTarball/openssl/include/openssl/macros.h:182:49: note: expanded from macro 'OSSL_DEPRECATEDIN_3_0' > # define OSSL_DEPRECATEDIN_3_0 OSSL_DEPRECATED(3.0) > ^ > workdir/UnpackedTarball/openssl/include/openssl/macros.h:62:52: note: expanded from macro 'OSSL_DEPRECATED' > # define OSSL_DEPRECATED(since) __attribute__((deprecated)) > ^ Change-Id: Ia9edc299b7cd4728fe32adbca8e1212170c328ba Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162248 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de> diff --git a/oox/source/crypto/CryptTools.cxx b/oox/source/crypto/CryptTools.cxx index ee68a8a50815..eb4c3f292cb7 100644 --- a/oox/source/crypto/CryptTools.cxx +++ b/oox/source/crypto/CryptTools.cxx @@ -10,6 +10,7 @@ #include <oox/crypto/CryptTools.hxx> #include <com/sun/star/uno/RuntimeException.hpp> +#include <sal/types.h> #include <config_oox.h> @@ -53,7 +54,9 @@ namespace struct hmac_delete { +SAL_WNODEPRECATED_DECLARATIONS_PUSH // 'HMAC_CTX_free' is deprecated void operator()(HMAC_CTX* p) { HMAC_CTX_free(p); } +SAL_WNODEPRECATED_DECLARATIONS_POP }; } @@ -108,7 +111,9 @@ struct CryptoImpl void setupCryptoHashContext(std::vector<sal_uInt8>& rKey, CryptoHashType eType) { +SAL_WNODEPRECATED_DECLARATIONS_PUSH // 'HMAC_CTX_new' is deprecated mpHmacContext.reset(HMAC_CTX_new()); +SAL_WNODEPRECATED_DECLARATIONS_POP const EVP_MD* aEvpMd = nullptr; switch (eType) { @@ -119,7 +124,9 @@ struct CryptoImpl case CryptoHashType::SHA512: aEvpMd = EVP_sha512(); break; } +SAL_WNODEPRECATED_DECLARATIONS_PUSH // 'HMAC_Init_ex' is deprecated HMAC_Init_ex(mpHmacContext.get(), rKey.data(), rKey.size(), aEvpMd, nullptr); +SAL_WNODEPRECATED_DECLARATIONS_POP } ~CryptoImpl() @@ -480,7 +487,9 @@ bool CryptoHash::update(std::vector<sal_uInt8>& rInput, sal_uInt32 nInputLength) #endif #if USE_TLS_OPENSSL +SAL_WNODEPRECATED_DECLARATIONS_PUSH // 'HMAC_Update' is deprecated return HMAC_Update(mpImpl->mpHmacContext.get(), rInput.data(), nActualInputLength) != 0; +SAL_WNODEPRECATED_DECLARATIONS_POP #elif USE_TLS_NSS return PK11_DigestOp(mpImpl->mContext, rInput.data(), nActualInputLength) == SECSuccess; #else @@ -493,7 +502,9 @@ std::vector<sal_uInt8> CryptoHash::finalize() std::vector<sal_uInt8> aHash(mnHashSize, 0); unsigned int nSizeWritten; #if USE_TLS_OPENSSL +SAL_WNODEPRECATED_DECLARATIONS_PUSH // 'HMAC_Final' is deprecated (void) HMAC_Final(mpImpl->mpHmacContext.get(), aHash.data(), &nSizeWritten); +SAL_WNODEPRECATED_DECLARATIONS_POP #elif USE_TLS_NSS PK11_DigestFinal(mpImpl->mContext, aHash.data(), &nSizeWritten, aHash.size()); #endif commit 3917e872fea196e8c0d9a57c7d2138e9c54ca55a Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Wed Feb 21 16:20:08 2024 +0600 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Wed Feb 21 21:34:55 2024 +0600 tdf#159813, tdf#159816: Use correct copied PaM This fixes both the assertion in CopyFlyInFlyImpl (tdf#159813) and crash in BigPtrArray::operator[] (tdf#159816). Change-Id: Ia3424e3a58c7d8fb3e1257dcdbf062fb893da8db Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163683 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sw/qa/extras/uiwriter/uiwriter8.cxx b/sw/qa/extras/uiwriter/uiwriter8.cxx index fd154c6c36a2..9dc75428e222 100644 --- a/sw/qa/extras/uiwriter/uiwriter8.cxx +++ b/sw/qa/extras/uiwriter/uiwriter8.cxx @@ -34,6 +34,7 @@ #include <ndtxt.hxx> #include <txtfld.hxx> #include <IDocumentFieldsAccess.hxx> +#include <IDocumentLayoutAccess.hxx> #include <IDocumentLinksAdministration.hxx> #include <IDocumentRedlineAccess.hxx> #include <rootfrm.hxx> @@ -2636,6 +2637,45 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf73483) assertXPath(pXml, para_style_path, "master-page-name", "Right_20_Page"); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest8, testTdf159816) +{ + createSwDoc(); + + SwDoc* pDoc = getSwDoc(); + CPPUNIT_ASSERT(pDoc); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + CPPUNIT_ASSERT(pWrtShell); + + // Add 5 empty paragraphs + pWrtShell->SplitNode(); + pWrtShell->SplitNode(); + pWrtShell->SplitNode(); + pWrtShell->SplitNode(); + pWrtShell->SplitNode(); + + // Add a bookmark at the very end + IDocumentMarkAccess& rIDMA(*pDoc->getIDocumentMarkAccess()); + rIDMA.makeMark(*pWrtShell->GetCursor(), "Mark", IDocumentMarkAccess::MarkType::BOOKMARK, + sw::mark::InsertMode::New); + + // Get coordinates of the end point in the document + SwRootFrame* pLayout = pDoc->getIDocumentLayoutAccess().GetCurrentLayout(); + SwFrame* pPage = pLayout->Lower(); + SwFrame* pBody = pPage->GetLower(); + SwFrame* pLastPara = pBody->GetLower()->GetNext()->GetNext()->GetNext()->GetNext()->GetNext(); + Point ptTo = pLastPara->getFrameArea().BottomRight(); + + pWrtShell->SelAll(); + + // Drag-n-drop to its own end + rtl::Reference<SwTransferable> xTransfer = new SwTransferable(*pWrtShell); + // Without the fix, this would crash: either in CopyFlyInFlyImpl (tdf#159813): + // Assertion failed: !pCopiedPaM || pCopiedPaM->End()->GetNode() == rRg.aEnd.GetNode() + // or in BigPtrArray::operator[] (tdf#159816): + // Assertion failed: idx < m_nSize + xTransfer->PrivateDrop(*pWrtShell, ptTo, /*bMove=*/true, /*bXSelection=*/true); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx index 6d8fa1f0a26f..3b57e0c6262e 100644 --- a/sw/source/core/doc/DocumentContentOperationsManager.cxx +++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx @@ -3653,11 +3653,16 @@ void DocumentContentOperationsManager::CopyWithFlyInFly( SwDoc& rDest = rInsPos.GetDoc(); SwNodeIndex aSavePos( rInsPos ); + SwPaM aCopiedPaM(rRg.aStart, rRg.aEnd); + if (pCopiedPaM) + aCopiedPaM = pCopiedPaM->first; + if (rRg.aStart != rRg.aEnd) { bool bEndIsEqualEndPos = rInsPos == rRg.aEnd.GetNode(); --aSavePos; SaveRedlEndPosForRestore aRedlRest( rInsPos, 0 ); + auto savedEndContentIndex = aCopiedPaM.End()->GetContentIndex(); // insert behind the already copied start node m_rDoc.GetNodes().CopyNodes( rRg, rInsPos, false, true ); @@ -3666,6 +3671,10 @@ void DocumentContentOperationsManager::CopyWithFlyInFly( if (bEndIsEqualEndPos) { const_cast<SwNodeIndex&>(rRg.aEnd).Assign(aSavePos.GetNode(), +1); + // pCopiedPaM->first now spans a range from the start of the original selection + // to the end of newly added text, and the insertion point is in the middle of + // that range. Adjust the local copy to cover the original copied PaM. + aCopiedPaM.End()->Assign(rRg.aEnd, savedEndContentIndex); } } @@ -3675,7 +3684,6 @@ void DocumentContentOperationsManager::CopyWithFlyInFly( // sw_fieldmarkhide: also needs to be done before making frames if (m_rDoc.getIDocumentMarkAccess()->getAllMarksCount()) { - SwPaM aRgTmp( rRg.aStart, rRg.aEnd ); SwPosition targetPos(aSavePos, SwNodeOffset(rRg.aStart != rRg.aEnd ? +1 : 0)); if (pCopiedPaM && rRg.aStart != pCopiedPaM->first.Start()->GetNode()) { @@ -3688,7 +3696,7 @@ void DocumentContentOperationsManager::CopyWithFlyInFly( targetPos = pCopiedPaM->second; } - sw::CopyBookmarks(pCopiedPaM ? pCopiedPaM->first : aRgTmp, targetPos); + sw::CopyBookmarks(aCopiedPaM, targetPos); } if (rRg.aStart != rRg.aEnd) @@ -3779,7 +3787,7 @@ void DocumentContentOperationsManager::CopyWithFlyInFly( { ::sw::UndoGuard const undoGuard(rDest.GetIDocumentUndoRedo()); - CopyFlyInFlyImpl(rRg, pCopiedPaM ? &pCopiedPaM->first : nullptr, + CopyFlyInFlyImpl(rRg, pCopiedPaM ? &aCopiedPaM : nullptr, // see comment below regarding use of pCopiedPaM->second (pCopiedPaM && rRg.aStart != pCopiedPaM->first.Start()->GetNode()) ? pCopiedPaM->second.GetNode()