[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.0' - 13 commits - basic/source cui/source download.lst external/neon external/nss lotuswordpro/qa lotuswordpro/source sc/inc sc/source sw/qa writerfilter/source

Michael Stahl mstahl at redhat.com
Thu Mar 10 18:41:45 UTC 2016


 basic/source/uno/namecont.cxx                             |   17 
 basic/source/uno/scriptcont.cxx                           |   10 
 cui/source/customize/acccfg.cxx                           |    2 
 download.lst                                              |    4 
 external/neon/neon.patch                                  |   47 -
 external/neon/neon_ne_set_request_flag.patch              |    6 
 external/nss/ExternalProject_nss.mk                       |    1 
 external/nss/UnpackedTarball_nss.mk                       |    2 
 external/nss/nss.cygwin64.in32bit.patch                   |   14 
 external/nss/nss.patch                                    |   42 +
 external/nss/ubsan.patch.0                                |   25 -
 lotuswordpro/qa/cppunit/data/fail/loop-2.lwp              |binary
 lotuswordpro/source/filter/lwpdivinfo.cxx                 |    8 
 lotuswordpro/source/filter/lwpfont.cxx                    |    2 
 lotuswordpro/source/filter/lwptablelayout.cxx             |    4 
 lotuswordpro/source/filter/lwptblformula.cxx              |    2 
 lotuswordpro/source/filter/xfilter/xfcontent.hxx          |   21 
 lotuswordpro/source/filter/xfilter/xfcontentcontainer.cxx |    2 
 lotuswordpro/source/filter/xfilter/xftextspan.cxx         |    6 
 sc/inc/scmatrix.hxx                                       |    8 
 sc/source/core/tool/interpr4.cxx                          |   14 
 sc/source/core/tool/interpr6.cxx                          |    4 
 sc/source/core/tool/scmatrix.cxx                          |   71 ++-
 sc/source/filter/oox/workbookhelper.cxx                   |    2 
 sc/source/ui/docshell/externalrefmgr.cxx                  |  330 +++++++++-----
 sw/qa/core/macros-test.cxx                                |   86 +++
 sw/qa/extras/rtfimport/data/tdf87034.rtf                  |   13 
 sw/qa/extras/rtfimport/rtfimport.cxx                      |    7 
 writerfilter/source/rtftok/rtfdocumentimpl.cxx            |    6 
 writerfilter/source/rtftok/rtfdocumentimpl.hxx            |    1 
 30 files changed, 544 insertions(+), 213 deletions(-)

New commits:
commit 4dbcbd039fe003323f73e37de9d3afc9e90510d9
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed Mar 9 12:55:25 2016 +0100

    nss: upgrade to release 3.22.2 fixing CVE-2016-1950
    
    Reviewed-on: https://gerrit.libreoffice.org/23070
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Stahl <mstahl at redhat.com>
    (cherry picked from commit 4d77c8088b52c649e80c12e208131a6844a53b12)
    
    Change-Id: Idc89778b488f2c84e5b0d495d2f44e623cc542b5
    Reviewed-on: https://gerrit.libreoffice.org/23104
    Reviewed-by: David Ostrovsky <david at ostrovsky.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit 7864fe9f7c83c865d1dc8e27ae652d2c89673f68)

diff --git a/download.lst b/download.lst
index f75608a..18b11a9 100644
--- a/download.lst
+++ b/download.lst
@@ -101,7 +101,7 @@ export MWAW_TARBALL := libmwaw-0.3.$(MWAW_VERSION_MICRO).tar.bz2
 export MYSQLCPPCONN_TARBALL := 7239a4430efd4d0189c4f24df67f08e5-mysql-connector-c++-1.1.4.tar.gz
 export MYTHES_TARBALL := a8c2c5b8f09e7ede322d5c602ff6a4b6-mythes-1.2.4.tar.gz
 export NEON_TARBALL := 231adebe5c2f78fded3e3df6e958878e-neon-0.30.1.tar.gz
-export NSS_TARBALL := d45f17e742acd490d1df7256cb4356b6-nss-3.22.1-with-nspr-4.12.tar.gz
+export NSS_TARBALL := 6b254cf2f8cb4b27a3f0b8b7b9966ea7-nss-3.22.2-with-nspr-4.12.tar.gz
 export ODFGEN_MD5SUM := 8716be5c22ae8353f9aaa380d74840dc
 export ODFGEN_VERSION_MICRO := 4
 export ODFGEN_TARBALL := libodfgen-0.1.$(ODFGEN_VERSION_MICRO).tar.bz2
commit e96bcdd9be457fcab46570e8b2a28224219f5bda
Author: David Ostrovsky <david at ostrovsky.org>
Date:   Fri Mar 4 19:59:18 2016 +0100

    nss: Fix pointer truncation from 'char *' to 'long'
    
    Change-Id: Ie1659c62cbf77f8b685fdf7d79cd62336fa99005
    Reviewed-on: https://gerrit.libreoffice.org/22916
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Norbert Thiebaud <nthiebaud at gmail.com>
    (cherry picked from commit 59907b36008010d87cc31b1f8ab581d5e4ac1c0b)
    Reviewed-on: https://gerrit.libreoffice.org/23103
    Reviewed-by: Michael Stahl <mstahl at redhat.com>
    Reviewed-by: David Ostrovsky <david at ostrovsky.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit 5e4f1ab7c0450000f46d2c21639e69b96c38b1f0)

diff --git a/external/nss/nss.patch b/external/nss/nss.patch
index 2cb23be..5483635 100644
--- a/external/nss/nss.patch
+++ b/external/nss/nss.patch
@@ -1,3 +1,14 @@
+--- a/nss.orig/nspr/pr/src/misc/prnetdb.c	2016-02-12 14:51:25.000000000 +0100
++++ b/nss/nspr/pr/src/misc/prnetdb.c	2016-03-04 19:23:00.462892600 +0100
+@@ -438,7 +438,7 @@
+ 	char *buf = *bufp;
+ 	PRIntn buflen = *buflenp;
+ 
+-	if (align && ((long)buf & (align - 1))) {
++	if (align && ((ptrdiff_t)buf & (align - 1))) {
+ 		PRIntn skip = align - ((ptrdiff_t)buf & (align - 1));
+ 		if (buflen < skip) {
+ 			return 0;
 diff -ru a/nspr/configure b/nspr/configure
 --- a/a/nspr/configure	2014-09-29 16:46:38.427423757 +0100
 +++ b/b/nspr/configure	2014-09-29 16:47:42.984012225 +0100
commit 412daa2005a3f002f8d161b0edf601ad63d5542c
Author: David Ostrovsky <david at ostrovsky.org>
Date:   Tue Feb 23 22:25:06 2016 +0100

    Bump nss to 3.22.1 and nspr to 4.12
    
    It seems like nss has activated -Werror, even though the code is not
    warning free: [1].  This applies also to the additional patches that
    would need to be patched to be a warning free patch, endless recursion.
    
    To avoid messing around with something like that: [2], we disable
    -Werror option for now. Also note, that [2] doesn't fix all warnings,
    but only part of them so that we let with unsolved non-trivially to
    fix warnings on different supported compilers if we would choose the
    warning-free-compilation-path.
    
    [1] https://groups.google.com/d/topic/mozilla.dev.tech.crypto/TgnF3tIMxJ0/discussion
    [2] https://git.fedorahosted.org/cgit/nss-pem.git/commit/?id=ec2b9a90623b1ec5adb6ebe8d6651b35854786ec
    
    Reviewed-on: https://gerrit.libreoffice.org/22650
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: David Ostrovsky <david at ostrovsky.org>
    (cherry picked from commit 486c91147c587febdacf3fa95d56633dbd703d5f)
    
    Change-Id: I762c03acede6c4eac715d3b0589061eeabbcc7c2
    Reviewed-on: https://gerrit.libreoffice.org/23102
    Reviewed-by: David Ostrovsky <david at ostrovsky.org>
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit 8e6ee22f2bffecff9d85058c6c21312585c6f1cc)

diff --git a/download.lst b/download.lst
index ca93af8..f75608a 100644
--- a/download.lst
+++ b/download.lst
@@ -101,7 +101,7 @@ export MWAW_TARBALL := libmwaw-0.3.$(MWAW_VERSION_MICRO).tar.bz2
 export MYSQLCPPCONN_TARBALL := 7239a4430efd4d0189c4f24df67f08e5-mysql-connector-c++-1.1.4.tar.gz
 export MYTHES_TARBALL := a8c2c5b8f09e7ede322d5c602ff6a4b6-mythes-1.2.4.tar.gz
 export NEON_TARBALL := 231adebe5c2f78fded3e3df6e958878e-neon-0.30.1.tar.gz
-export NSS_TARBALL := 478e0e90ebc4a90159549e77021021fd-nss-3.19.4-with-nspr-4.10.10.tar.gz
+export NSS_TARBALL := d45f17e742acd490d1df7256cb4356b6-nss-3.22.1-with-nspr-4.12.tar.gz
 export ODFGEN_MD5SUM := 8716be5c22ae8353f9aaa380d74840dc
 export ODFGEN_VERSION_MICRO := 4
 export ODFGEN_TARBALL := libodfgen-0.1.$(ODFGEN_VERSION_MICRO).tar.bz2
diff --git a/external/nss/ExternalProject_nss.mk b/external/nss/ExternalProject_nss.mk
index 17ea6f1..bd64971 100644
--- a/external/nss/ExternalProject_nss.mk
+++ b/external/nss/ExternalProject_nss.mk
@@ -22,6 +22,7 @@ $(call gb_ExternalProject_get_state_target,nss,configure):
 		nspr/configure --includedir=$(call gb_UnpackedTarball_get_dir,nss)/mozilla/dist/out/include \
 			$(if $(CROSS_COMPILING),--build=$(BUILD_PLATFORM) --host=$(HOST_PLATFORM)) \
 			$(if $(filter MSC-X86_64,$(COM)-$(CPUNAME)),--enable-64bit) \
+			$(if $(filter MSC-INTEL,$(COM)-$(CPUNAME)),--host=i686-pc-cygwin) \
 	,,nss_configure.log)
 
 ifeq ($(OS),WNT)
diff --git a/external/nss/UnpackedTarball_nss.mk b/external/nss/UnpackedTarball_nss.mk
index 1b9f45d..803e809 100644
--- a/external/nss/UnpackedTarball_nss.mk
+++ b/external/nss/UnpackedTarball_nss.mk
@@ -26,6 +26,8 @@ $(eval $(call gb_UnpackedTarball_add_patches,nss,\
         external/nss/nss-chromium-nss-static.patch \
         external/nss/nss-more-static.patch \
         external/nss/nss-ios.patch) \
+	$(if $(filter MSC-INTEL,$(COM)-$(CPUNAME)), \
+		external/nss/nss.cygwin64.in32bit.patch) \
 ))
 
 # nss-pem is only needed for internal curl to read the NSS CA database
diff --git a/external/nss/nss.cygwin64.in32bit.patch b/external/nss/nss.cygwin64.in32bit.patch
new file mode 100755
index 0000000..b00761a
--- /dev/null
+++ b/external/nss/nss.cygwin64.in32bit.patch
@@ -0,0 +1,14 @@
+This fixes architecture mismatch, when building
+on Cygwin 64bit and in 32bit mode
+diff -ru nss.orig/nss/Makefile nss/nss/Makefile
+--- a/nss.orig/nss/Makefile       2016-02-26 01:00:52.146713100 +0100
++++ b/nss/nss/Makefile    2016-02-26 01:02:05.303560100 +0100
+@@ -59,6 +59,8 @@
+ # Translate coreconf build options to NSPR configure options.
+ #
+
++NSPR_CONFIGURE_OPTS += --host=i686-pc-cygwin
++
+ ifeq ($(OS_TARGET),Android)
+ NSPR_CONFIGURE_OPTS += --with-android-ndk=$(ANDROID_NDK) \
+                        --target=$(ANDROID_PREFIX) \
diff --git a/external/nss/nss.patch b/external/nss/nss.patch
index e555d6e..2cb23be 100644
--- a/external/nss/nss.patch
+++ b/external/nss/nss.patch
@@ -40,24 +40,34 @@ diff -ru a/nss/cmd/platlibs.mk b/nss/cmd/platlibs.mk
  endif
  endif
  
-diff -ru a/nss/coreconf/arch.mk b/nss/coreconf/arch.mk
---- a/a/nss/coreconf/arch.mk	2014-09-29 16:46:38.175421471 +0100
-+++ b/b/nss/coreconf/arch.mk	2014-09-29 16:47:42.986012244 +0100
-@@ -280,10 +280,15 @@
+diff -ru nss.orig/nss/coreconf/arch.mk nss/nss/coreconf/arch.mk
+--- a/nss.orig/nss/coreconf/arch.mk	2016-02-12 15:36:18.000000000 +0100
++++ b/nss/nss/coreconf/arch.mk	2016-02-23 20:48:31.595941079 +0100
+@@ -280,15 +280,21 @@
  # IMPL_STRATEGY may be defined too.
  #
  
+-ifdef CROSS_COMPILE
+-OBJDIR_NAME = $(OS_TARGET)$(OS_RELEASE)$(CPU_TAG)$(LIBC_TAG)$(IMPL_STRATEGY)$(OBJDIR_TAG).OBJ
+-else
 -OBJDIR_NAME = $(OS_TARGET)$(OS_RELEASE)$(CPU_TAG)$(COMPILER_TAG)$(LIBC_TAG)$(IMPL_STRATEGY)$(OBJDIR_TAG).OBJ
+-endif
 +# OBJDIR_NAME is used to build the directory containing the built objects, for 
 +# example mozilla/dist/Linux2.6_x86_glibc_PTH_DBG.OBJ
 +# We need to deliver the contents of that folder into instdir. To make that 
 +# easier in the makefile we rename this directory to "out". 
++#ifdef CROSS_COMPILE
++#OBJDIR_NAME = $(OS_TARGET)$(OS_RELEASE)$(CPU_TAG)$(LIBC_TAG)$(IMPL_STRATEGY)$(OBJDIR_TAG).OBJ
++#else
 +#OBJDIR_NAME = $(OS_TARGET)$(OS_RELEASE)$(CPU_TAG)$(COMPILER_TAG)$(LIBC_TAG)$(IMPL_STRATEGY)$(OBJDIR_TAG).OBJ
++#endif
 +OBJDIR_NAME = out
  
+ 
  ifeq (,$(filter-out WIN%,$(OS_TARGET)))
 -ifndef BUILD_OPT
 +ifdef THIS_HAS_BEEN_DISABLED_TO_GET_out
++
  #
  # Define USE_DEBUG_RTL if you want to use the debug runtime library
  # (RTL) in the debug build
@@ -151,3 +161,16 @@ diff -ru a/nss/Makefile b/nss/Makefile
  #! gmake
  #
  # This Source Code Form is subject to the terms of the Mozilla Public
+diff -ru nss.orig/nss/coreconf/Werror.mk nss/nss/coreconf/Werror.mk
+--- a/nss.orig/nss/coreconf/Werror.mk	2016-02-12 15:36:18.000000000 +0100
++++ b/nss/nss/coreconf/Werror.mk	2016-02-23 23:58:15.119584046 +0100
+@@ -60,7 +60,8 @@
+   endif #ndef NSS_ENABLE_WERROR
+ 
+   ifeq ($(NSS_ENABLE_WERROR),1)
+-    WARNING_CFLAGS += -Werror
++# We do not treat warnings as errors.
++#    WARNING_CFLAGS += -Werror
+   else
+     # Old versions of gcc (< 4.8) don't support #pragma diagnostic in functions.
+     # Use this to disable use of that #pragma and the warnings it suppresses.
diff --git a/external/nss/ubsan.patch.0 b/external/nss/ubsan.patch.0
index 956e07b..ccf04b9 100644
--- a/external/nss/ubsan.patch.0
+++ b/external/nss/ubsan.patch.0
@@ -1,24 +1,12 @@
---- nss/lib/certdb/crl.c
-+++ nss/lib/certdb/crl.c
-@@ -2150,7 +2150,7 @@
+diff -ru nss.orig/nss/lib/certdb/crl.c nss/nss/lib/certdb/crl.c
+--- nss/lib/certdb/crl.c	2016-02-12 15:36:18.000000000 +0100
++++ nss/lib/certdb/crl.c	2016-02-23 20:57:17.067924598 +0100
+@@ -1982,7 +1982,7 @@
          return SECSuccess;
      }
      /* all CRLs are good, sort them by thisUpdate */
--    qsort(cache->crls, cache->ncrls, sizeof(CachedCrl*),
-+    if (cache->ncrls != 0) qsort(cache->crls, cache->ncrls, sizeof(CachedCrl*),
-           SortCRLsByThisUpdate);
- 
-     if (cache->ncrls)
---- nss/lib/libpkix/pkix/util/pkix_tools.h
-+++ nss/lib/libpkix/pkix/util/pkix_tools.h
-@@ -1458,8 +1458,8 @@
- 
- extern PRLogModuleInfo *pkixLog;
- 
--#define PKIX_MAGIC_HEADER           LL_INIT(0xFEEDC0FF, 0xEEFACADE)
--#define PKIX_MAGIC_HEADER_DESTROYED LL_INIT(0xBAADF00D, 0xDEADBEEF)
-+#define PKIX_MAGIC_HEADER           LL_INIT(0xFEEDC0FFU, 0xEEFACADEU)
-+#define PKIX_MAGIC_HEADER_DESTROYED LL_INIT(0xBAADF00DU, 0xDEADBEEFU)
- 
- /* see source file for function documentation */
+-    qsort(cache->crls, cache->ncrls, sizeof(CachedCrl*), SortCRLsByThisUpdate);
++    if (cache->ncrls != 0) qsort(cache->crls, cache->ncrls, sizeof(CachedCrl*), SortCRLsByThisUpdate);
  
+     if (cache->ncrls) {
+         /* pick the newest CRL */
commit f3341434d006159ff686dd3e51fbcd5686bb94fd
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Jun 12 08:22:22 2015 +0200

    external/nss: -fsanitize=nonnull-attribute
    
    Change-Id: Ic3a20f56250d99a347df5deaf785800a2f96e470
    (cherry picked from commit 8d2ac08383f894f428da63f4653d0cbd6649e0db)
    Reviewed-on: https://gerrit.libreoffice.org/23101
    Reviewed-by: Michael Stahl <mstahl at redhat.com>
    Tested-by: Michael Stahl <mstahl at redhat.com>
    (cherry picked from commit b99a91b790eedbfddb1ee93c183adb6d2405285e)

diff --git a/external/nss/ubsan.patch.0 b/external/nss/ubsan.patch.0
index 298ca40..956e07b 100644
--- a/external/nss/ubsan.patch.0
+++ b/external/nss/ubsan.patch.0
@@ -1,3 +1,14 @@
+--- nss/lib/certdb/crl.c
++++ nss/lib/certdb/crl.c
+@@ -2150,7 +2150,7 @@
+         return SECSuccess;
+     }
+     /* all CRLs are good, sort them by thisUpdate */
+-    qsort(cache->crls, cache->ncrls, sizeof(CachedCrl*),
++    if (cache->ncrls != 0) qsort(cache->crls, cache->ncrls, sizeof(CachedCrl*),
+           SortCRLsByThisUpdate);
+ 
+     if (cache->ncrls)
 --- nss/lib/libpkix/pkix/util/pkix_tools.h
 +++ nss/lib/libpkix/pkix/util/pkix_tools.h
 @@ -1458,8 +1458,8 @@
commit f2aa421f2609f8b54120926b0906693e44470f44
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Feb 10 08:59:01 2016 +0100

    tdf#87034 RTF import: fix multiple superscripts after footnote ...
    
    ... in the same paragraph. The intention was to avoid replaying the
    supertext buffer and using its contents as a custom footnote mark at the
    same time. However, it's enough to check if the buffer is empty to do
    so, and that avoids the mis-import of the bugdoc as well.
    
    (cherry picked from commit 93faf178195ca974747849879266783884ae27c5)
    
    Conflicts:
    	sw/qa/extras/rtfimport/rtfimport.cxx
    
    Change-Id: I1e3b0c7f0c6d8eb8250d8b1d0d7d196039c40e79
    Reviewed-on: https://gerrit.libreoffice.org/23084
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit 05ab13e44ab45953c4d4d18d8c9070698c041969)

diff --git a/sw/qa/extras/rtfimport/data/tdf87034.rtf b/sw/qa/extras/rtfimport/data/tdf87034.rtf
new file mode 100644
index 0000000..16f322c
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/tdf87034.rtf
@@ -0,0 +1,13 @@
+{\rtf1
+\pard\plain A
+{\chftn
+{\footnote\chftn F
+}
+}
+B
+{\super 3}
+C
+{\super 4}
+D
+\par
+}
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index 16e0c4b..f1d0927 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -2364,6 +2364,13 @@ DECLARE_RTFIMPORT_TEST(testTdf96308Tabpos, "tdf96308-tabpos.rtf")
     CPPUNIT_ASSERT(!aTabStops.hasElements());
 }
 
+DECLARE_RTFIMPORT_TEST(testTdf87034, "tdf87034.rtf")
+{
+    // This was A1BC34D, i.e. the first "super" text portion was mis-imported,
+    // and was inserted instead right before the second "super" text portion.
+    CPPUNIT_ASSERT_EQUAL(OUString("A1B3C4D"), getParagraph(1)->getString());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index be5a966..c6f3d32 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -241,7 +241,6 @@ RTFDocumentImpl::RTFDocumentImpl(uno::Reference<uno::XComponentContext> const& x
       m_nBackupTopLevelCurrentCellX(0),
       m_aTableBufferStack(1), // create top-level buffer already
       m_aSuperBuffer(),
-      m_bHasFootnote(false),
       m_pSuperstream(nullptr),
       m_nStreamType(0),
       m_nHeaderFooterPositions(),
@@ -1695,7 +1694,6 @@ RTFError RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
                 if (aKeyword.equals("\\ftnalt"))
                     nId = NS_ooxml::LN_endnote;
 
-                m_bHasFootnote = true;
                 if (m_aStates.top().pCurrentBuffer == &m_aSuperBuffer)
                     m_aStates.top().pCurrentBuffer = nullptr;
                 bool bCustomMark = false;
@@ -6055,10 +6053,8 @@ RTFError RTFDocumentImpl::popState()
     {
         OSL_ASSERT(!m_aStates.empty() && m_aStates.top().pCurrentBuffer == nullptr);
 
-        if (!m_bHasFootnote)
+        if (!m_aSuperBuffer.empty())
             replayBuffer(m_aSuperBuffer, nullptr, nullptr);
-
-        m_bHasFootnote = false;
     }
 
     return RTFError::OK;
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index ae320ad..863b952 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -522,7 +522,6 @@ private:
     /// Buffered superscript, till footnote is reached (or not).
     RTFBuffer_t m_aSuperBuffer;
 
-    bool m_bHasFootnote;
     /// Superstream of this substream.
     RTFDocumentImpl* m_pSuperstream;
     /// Type of the stream: header, footer, footnote, etc.
commit 355925efcc284a254170640cd79bee4ae9fd1627
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Mar 9 16:18:55 2016 +0100

    Resolves: tdf#95226 second case, stack error count in JumpMatrix context
    
    For the early bail out on errors to work correctly and not prematurely
    end calculations the current error function needs to be stacked in
    JumpMatrix context, otherwise we may end up with
    ((nErrorFunction=74)>=(nErrorFunctionCount=2)) or some such..
    
    (cherry picked from commit 62b40429946c0e5021912072dc79a60fc11fce06)
    
    Change-Id: I3559e15180694961585db92f6aa98a46430ae372
    Reviewed-on: https://gerrit.libreoffice.org/23091
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit 070fbda4edafb27c91c856039880099014f2b53f)

diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index 44e25c7..6ed55dd 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -75,6 +75,7 @@
 #include <vbahelper/vbaaccesshelper.hxx>
 #include <memory>
 #include <boost/scoped_array.hpp>
+#include <stack>
 
 using namespace com::sun::star;
 using namespace formula;
@@ -3564,6 +3565,7 @@ StackVar ScInterpreter::Interpret()
     sal_uLong nRetIndexExpr = 0;
     sal_uInt16 nErrorFunction = 0;
     sal_uInt16 nErrorFunctionCount = 0;
+    std::stack<sal_uInt16> aErrorFunctionStack;
     sal_uInt16 nStackBase;
 
     nGlobalError = 0;
@@ -4094,7 +4096,19 @@ StackVar ScInterpreter::Interpret()
             else
                 nLevel = 0;
             if ( nLevel == 1 || (nLevel == 2 && aCode.IsEndOfPath()) )
+            {
+                if (nLevel == 1)
+                    aErrorFunctionStack.push( nErrorFunction);
                 bGotResult = JumpMatrix( nLevel );
+                if (aErrorFunctionStack.empty())
+                    assert(!"ScInterpreter::Interpret - aErrorFunctionStack empty in JumpMatrix context");
+                else
+                {
+                    nErrorFunction = aErrorFunctionStack.top();
+                    if (bGotResult)
+                        aErrorFunctionStack.pop();
+                }
+            }
             else
                 pJumpMatrix = NULL;
         } while ( bGotResult );
commit b3822ee713d7f25b43f99553ada8a6f0a81e4d44
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Mar 8 12:09:55 2016 +0000

    avoid infinite regress in busted documents
    
    Change-Id: I639617e41cd9a9a51a3dd3efa32ac1cf2991b9d2
    (cherry picked from commit f16ceae46dd8f3974a379c6fb07feaffb8012b25)
    Reviewed-on: https://gerrit.libreoffice.org/23031
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>
    (cherry picked from commit 69e4ce0716f7998dbeab954a43b912e72f0f4947)

diff --git a/lotuswordpro/qa/cppunit/data/fail/loop-2.lwp b/lotuswordpro/qa/cppunit/data/fail/loop-2.lwp
new file mode 100644
index 0000000..6342cc5
Binary files /dev/null and b/lotuswordpro/qa/cppunit/data/fail/loop-2.lwp differ
diff --git a/lotuswordpro/source/filter/lwpdivinfo.cxx b/lotuswordpro/source/filter/lwpdivinfo.cxx
index 11d4f0e..80884f7 100644
--- a/lotuswordpro/source/filter/lwpdivinfo.cxx
+++ b/lotuswordpro/source/filter/lwpdivinfo.cxx
@@ -112,15 +112,11 @@ void LwpDivInfo::Read()
     m_FillerPageTextID.ReadIndexed(m_pObjStrm);
 
     // read external file object stuff
-#if !defined(NDEBUG)
-    sal_uInt16 type =
-#endif
-    m_pObjStrm->QuickReaduInt16();
+    sal_uInt16 type = m_pObjStrm->QuickReaduInt16();
     //cpExternalFile = LNULL;
 
-    assert(type==0);
+    SAL_WARN_IF(type != 0, "lwp", "should be 0");
     m_pObjStrm->SkipExtra();
-
 }
 
 void LwpDivInfo::SkipFront()
diff --git a/lotuswordpro/source/filter/lwpfont.cxx b/lotuswordpro/source/filter/lwpfont.cxx
index 4307d29..79e94bf 100644
--- a/lotuswordpro/source/filter/lwpfont.cxx
+++ b/lotuswordpro/source/filter/lwpfont.cxx
@@ -262,7 +262,7 @@ void LwpFontTable::Read(LwpObjectStream *pStrm)
 
 OUString LwpFontTable::GetFaceName(sal_uInt16 index) //index: start from 1
 {
-    assert(index <= m_nCount && index > 0);
+    SAL_WARN_IF(index > m_nCount || index <= 0, "lwp", "bad font index");
     return (index <= m_nCount && index > 0) ? m_pFontEntries[index-1].GetFaceName() : OUString();
 }
 
diff --git a/lotuswordpro/source/filter/lwptablelayout.cxx b/lotuswordpro/source/filter/lwptablelayout.cxx
index 6f1b73c..ec18542 100644
--- a/lotuswordpro/source/filter/lwptablelayout.cxx
+++ b/lotuswordpro/source/filter/lwptablelayout.cxx
@@ -218,13 +218,13 @@ double LwpSuperTableLayout::GetTableWidth()
         LwpTableLayout* pTableLayout = GetTableLayout();
         if(!pTableLayout)
         {
-            assert(false);
+            SAL_WARN("lwp", "missing table layout, early return");
             return 0;
         }
         LwpTable *pTable = pTableLayout->GetTable();
         if(!pTable)
         {
-            assert(false);
+            SAL_WARN("lwp", "missing table, early return");
             return 0;
         }
         double dDefaultWidth = pTable->GetWidth();
diff --git a/lotuswordpro/source/filter/lwptblformula.cxx b/lotuswordpro/source/filter/lwptblformula.cxx
index 7f8ea4a..699b7ce 100644
--- a/lotuswordpro/source/filter/lwptblformula.cxx
+++ b/lotuswordpro/source/filter/lwptblformula.cxx
@@ -389,7 +389,7 @@ void LwpFormulaInfo::Read()
         }
         else
         {
-            assert(false);
+            SAL_WARN("lwp", "missing row list");
         }
     }
 //  sal_uInt8 cFlags = (sal_uInt8) m_pObjStrm->QuickReaduInt16(); // written as a sal_uInt16
diff --git a/lotuswordpro/source/filter/xfilter/xfcontent.hxx b/lotuswordpro/source/filter/xfilter/xfcontent.hxx
index 2d1dfa7..29a2fd0 100644
--- a/lotuswordpro/source/filter/xfilter/xfcontent.hxx
+++ b/lotuswordpro/source/filter/xfilter/xfcontent.hxx
@@ -64,6 +64,7 @@
 
 #include <rtl/ustring.hxx>
 #include <salhelper/simplereferenceobject.hxx>
+#include <stdexcept>
 
 #include "xfdefs.hxx"
 
@@ -92,14 +93,28 @@ public:
      */
     OUString   GetStyleName() {return m_strStyleName;}
 
-    virtual void ToXml(IXFStream * stream) = 0;
+    void DoToXml(IXFStream* stream)
+    {
+        if (m_bDoingToXml)
+            throw std::runtime_error("recursion in content");
+        m_bDoingToXml = true;
+        ToXml(stream);
+        m_bDoingToXml = false;
+    }
 
 protected:
-    XFContent() {}
+    XFContent()
+        : m_bDoingToXml(false)
+    {
+    }
+
+    virtual void ToXml(IXFStream* stream) = 0;
 
     virtual ~XFContent() {}
 
-    OUString   m_strStyleName;
+    OUString m_strStyleName;
+private:
+    bool m_bDoingToXml;
 };
 
 #endif
diff --git a/lotuswordpro/source/filter/xfilter/xfcontentcontainer.cxx b/lotuswordpro/source/filter/xfilter/xfcontentcontainer.cxx
index ece407e..4e3576d 100644
--- a/lotuswordpro/source/filter/xfilter/xfcontentcontainer.cxx
+++ b/lotuswordpro/source/filter/xfilter/xfcontentcontainer.cxx
@@ -131,7 +131,7 @@ void    XFContentContainer::ToXml(IXFStream *pStrm)
     {
         XFContent *pContent = it->get();
         if( pContent )
-            pContent->ToXml(pStrm);
+            pContent->DoToXml(pStrm);
     }
 }
 
diff --git a/lotuswordpro/source/filter/xfilter/xftextspan.cxx b/lotuswordpro/source/filter/xfilter/xftextspan.cxx
index 4de6bad..90f6e32 100644
--- a/lotuswordpro/source/filter/xfilter/xftextspan.cxx
+++ b/lotuswordpro/source/filter/xfilter/xftextspan.cxx
@@ -112,7 +112,7 @@ void    XFTextSpan::ToXml(IXFStream *pStrm)
     {
         XFContent *pContent = it->get();
         if( pContent )
-            pContent->ToXml(pStrm);
+            pContent->DoToXml(pStrm);
     }
 
     pStrm->EndElement( "text:span" );
@@ -135,7 +135,7 @@ void    XFTextSpanStart::ToXml(IXFStream *pStrm)
     {
         XFContent *pContent = it->get();
         if( pContent )
-            pContent->ToXml(pStrm);
+            pContent->DoToXml(pStrm);
     }
 }
 void    XFTextSpanEnd::ToXml(IXFStream *pStrm)
@@ -145,7 +145,7 @@ void    XFTextSpanEnd::ToXml(IXFStream *pStrm)
     {
         XFContent *pContent = it->get();
         if( pContent )
-            pContent->ToXml(pStrm);
+            pContent->DoToXml(pStrm);
     }
     pStrm->EndElement( "text:span" );
 }
commit a347c44364f06514adf60c954557a6103726bdfa
Author: Yousuf Philips <philipz85 at hotmail.com>
Date:   Mon Feb 22 23:23:09 2016 +0400

    tdf#97942 Return Ctrl+Shift+Space to the keyword customize
    
    Change-Id: I4a886a9312a4b4afbe2451b88941b72dc5c6dadc
    Reviewed-on: https://gerrit.libreoffice.org/22621
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    (cherry picked from commit f6f66bd6a102239f3d24c257298dc1f6c2fd8199)
    Reviewed-on: https://gerrit.libreoffice.org/22671
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit a0dcfdf37c14f16fe88ed9c0c9f096e2cea1fc03)

diff --git a/cui/source/customize/acccfg.cxx b/cui/source/customize/acccfg.cxx
index b3511e9..5b31656 100644
--- a/cui/source/customize/acccfg.cxx
+++ b/cui/source/customize/acccfg.cxx
@@ -308,6 +308,7 @@ static const sal_uInt16 KEYCODE_ARRAY[] =
     KEY_SHIFT | KEY_MOD1 | KEY_PAGEDOWN,
     KEY_SHIFT | KEY_MOD1 | KEY_RETURN,
     KEY_SHIFT | KEY_MOD1 | KEY_ESCAPE,
+    KEY_SHIFT | KEY_MOD1 | KEY_SPACE,
     KEY_SHIFT | KEY_MOD1 | KEY_BACKSPACE,
     KEY_SHIFT | KEY_MOD1 | KEY_INSERT,
     KEY_SHIFT | KEY_MOD1 | KEY_DELETE,
@@ -454,6 +455,7 @@ static const sal_uInt16 KEYCODE_ARRAY[] =
     KEY_SHIFT | KEY_MOD2 | KEY_PAGEDOWN,
     KEY_SHIFT | KEY_MOD2 | KEY_RETURN,
     KEY_SHIFT | KEY_MOD2 | KEY_ESCAPE,
+    KEY_SHIFT | KEY_MOD2 | KEY_SPACE,
     KEY_SHIFT | KEY_MOD2 | KEY_BACKSPACE,
     KEY_SHIFT | KEY_MOD2 | KEY_INSERT,
     KEY_SHIFT | KEY_MOD2 | KEY_DELETE,
commit c6a3f70173b6ed4ad8106628a5753281f3823905
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Mar 2 22:48:01 2016 +0100

    Resolves: tdf#98297 exclude error values from COUNT in array/matrix
    
    Backport of b2f5336b08b5f638f890a626eb2aeefaf499a79b
    
    Change-Id: I04ef53b8880243b3548e1b7fd926690dcb4a2137
    Reviewed-on: https://gerrit.libreoffice.org/22846
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit 84f8fa501ac772b40639d7b6e95ebeb752b01bf5)

diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx
index 5a5ff95..a4b38df 100644
--- a/sc/inc/scmatrix.hxx
+++ b/sc/inc/scmatrix.hxx
@@ -372,7 +372,7 @@ public:
     IterateResult Sum(bool bTextAsZero) const;
     IterateResult SumSquare(bool bTextAsZero) const;
     IterateResult Product(bool bTextAsZero) const;
-    size_t Count(bool bCountStrings) const;
+    size_t Count(bool bCountStrings, bool bCountErrors) const;
     size_t MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const;
     size_t MatchStringInColumns(const svl::SharedString& rStr, size_t nCol1, size_t nCol2) const;
 
diff --git a/sc/source/core/tool/interpr6.cxx b/sc/source/core/tool/interpr6.cxx
index e02abbc..6d5e624 100644
--- a/sc/source/core/tool/interpr6.cxx
+++ b/sc/source/core/tool/interpr6.cxx
@@ -376,10 +376,10 @@ void IterateMatrix(
         }
         break;
         case ifCOUNT:
-            rCount += pMat->Count(bTextAsZero);
+            rCount += pMat->Count(bTextAsZero, false);  // do not count error values
         break;
         case ifCOUNT2:
-            rCount += pMat->Count(true);
+            rCount += pMat->Count(true, true);          // do count error values
         break;
         case ifPRODUCT:
         {
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index 328a4ba..55ed380 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -284,7 +284,7 @@ public:
     ScMatrix::IterateResult Sum(bool bTextAsZero) const;
     ScMatrix::IterateResult SumSquare(bool bTextAsZero) const;
     ScMatrix::IterateResult Product(bool bTextAsZero) const;
-    size_t Count(bool bCountStrings) const;
+    size_t Count(bool bCountStrings, bool bCountErrors) const;
     size_t MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const;
     size_t MatchStringInColumns(const svl::SharedString& rStr, size_t nCol1, size_t nCol2) const;
 
@@ -1105,8 +1105,10 @@ class CountElements : std::unary_function<MatrixImplType::element_block_node_typ
 {
     size_t mnCount;
     bool mbCountString;
+    bool mbCountErrors;
 public:
-    CountElements(bool bCountString) : mnCount(0), mbCountString(bCountString) {}
+    CountElements(bool bCountString, bool bCountErrors) :
+        mnCount(0), mbCountString(bCountString), mbCountErrors(bCountErrors) {}
 
     size_t getCount() const { return mnCount; }
 
@@ -1115,6 +1117,20 @@ public:
         switch (node.type)
         {
             case mdds::mtm::element_numeric:
+                mnCount += node.size;
+                if (!mbCountErrors)
+                {
+                    typedef MatrixImplType::numeric_block_type block_type;
+
+                    block_type::const_iterator it = block_type::begin(*node.data);
+                    block_type::const_iterator itEnd = block_type::end(*node.data);
+                    for (; it != itEnd; ++it)
+                    {
+                        if (!::rtl::math::isFinite(*it))
+                            --mnCount;
+                    }
+                }
+            break;
             case mdds::mtm::element_boolean:
                 mnCount += node.size;
             break;
@@ -1719,9 +1735,9 @@ ScMatrix::IterateResult ScMatrixImpl::Product(bool bTextAsZero) const
     return aRes;
 }
 
-size_t ScMatrixImpl::Count(bool bCountStrings) const
+size_t ScMatrixImpl::Count(bool bCountStrings, bool bCountErrors) const
 {
-    CountElements aFunc(bCountStrings);
+    CountElements aFunc(bCountStrings, bCountErrors);
     maMat.walk(aFunc);
     return aFunc.getCount();
 }
@@ -2518,9 +2534,9 @@ ScMatrix::IterateResult ScMatrix::Product(bool bTextAsZero) const
     return pImpl->Product(bTextAsZero);
 }
 
-size_t ScMatrix::Count(bool bCountStrings) const
+size_t ScMatrix::Count(bool bCountStrings, bool bCountErrors) const
 {
-    return pImpl->Count(bCountStrings);
+    return pImpl->Count(bCountStrings, bCountErrors);
 }
 
 size_t ScMatrix::MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const
commit f25ccb80127ab2fff549ddb7e68c9f1d33295566
Author: Eike Rathke <erack at redhat.com>
Date:   Mon Mar 7 13:20:54 2016 +0100

    Resolves: tdf#98389 check memory requirement of matrix
    
    Attachment 123203 of tdf#98389 has external references of the form
    [1]Data!$1:$1048576
    which effectively address the entire cell range of sheet Data and
    allocating a matrix for a billion cells attempted to allocate 8GB+xGB of
    memory which the system said no-no ...
    
    Some brave soul along the road once decided that a check on the number
    of elements wasn't needed anymore and dared to remove it during
    refactoring.. This change reintroduces the check and adds it also to
    other places that try to instanciate or resize a matrix.
    
    When allocation of a matrix for an external range reference fails it is
    checked whether the request is for such nasty entire rows or entire
    columns ranges and if so tries to shrink the range to the actual data
    area used, which at least in this case helps and works.
    
    Additionally it fixes a long standing bug in the cached area to array
    mapping which caused the cache to not be hit but instead the matrix was
    aquired over and over again for the same range, causing a serious
    performance bottle neck specifically for VLOOKUP and related functions
    where the same external range is used in a lot of cells.
    
    (cherry picked from commit 9e60bbdb3aa5f80ca80c9c4fdf7accd12c4a5d1c)
    
    Change in convertToTokenArray() backported to older code flow.
    
    disable means Enable(false), not true.. tdf#98389 related
    
    EnableAdjustHeight(true) lead to the side effect that when clearing the
    range of a pivot table during import, formulas in the same rows were
    recalculated with then empty data. Through xSheetOp->clearContents() in
    PivotTable::finalizeImport() of
    sc/source/filter/oox/pivottablebuffer.cxx
    
    In the case of the bugdoc attached to tdf#98389 that lead to all
    VLOOKUP() calls resulting in #N/A errors because an empty string was
    looked up.
    
    (cherry picked from commit 088ba465d6bb0931c7034d564a3077e21078cb13)
    
    e629ce871d255cc871671165c4da974f21041cec
    
    Backported to ScMatrix implementation of 5-0.
    
    setCellRangeData: check matrix size before operating, tdf#98389 follow-up
    
    Now that we can have the one element error matrix we can't blindly call
    ExecuteOperation() on it that would access elements out of bounds.
    
    (cherry picked from commit 9cae3a88587deaf22ee83b2e36487013a1220a3b)
    
    Backported to older code flow.
    
    b6e5525f685c9324235f128a943dd716ea7a3fca
    
    Change-Id: I35f67b48e665bf1cc8d672325c32b889f2e05c57
    Reviewed-on: https://gerrit.libreoffice.org/23003
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit 23510e0c61dc92eed37129070d2a2b349b43d686)

diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx
index f1fbe8e..5a5ff95 100644
--- a/sc/inc/scmatrix.hxx
+++ b/sc/inc/scmatrix.hxx
@@ -160,6 +160,12 @@ public:
 #endif
     }
 
+    /** Checks nC or nR for zero and uses GetElementsMax() whether a matrix of
+        the size of nC*nR could be allocated. A zero size (both nC and nR zero)
+        matrix is allowed for later resize.
+     */
+    bool static IsSizeAllocatable( SCSIZE nC, SCSIZE nR );
+
     /// Value or boolean.
     inline static bool IsValueType( ScMatValType nType )
     {
diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index c5c42f3..328a4ba 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -2157,25 +2157,52 @@ void ScMatrix::DecRef() const
         delete this;
 }
 
-ScMatrix::ScMatrix( SCSIZE nC, SCSIZE nR) :
-    pImpl(new ScMatrixImpl(nC, nR)), nRefCnt(0)
+bool ScMatrix::IsSizeAllocatable( SCSIZE nC, SCSIZE nR )
 {
     SAL_WARN_IF( !nC, "sc", "ScMatrix with 0 columns!");
     SAL_WARN_IF( !nR, "sc", "ScMatrix with 0 rows!");
+    // 0-size matrix is valid, it could be resized later.
+    if ((nC && !nR) || (!nC && nR))
+    {
+        SAL_WARN( "sc", "ScMatrix one-dimensional zero: " << nC << " columns * " << nR << " rows");
+        return false;
+    }
+    if (nC && nR && (nC > (ScMatrix::GetElementsMax() / nR)))
+    {
+        SAL_WARN( "sc", "ScMatrix overflow: " << nC << " columns * " << nR << " rows");
+        return false;
+    }
+    return true;
+}
+
+ScMatrix::ScMatrix( SCSIZE nC, SCSIZE nR) :
+    pImpl(nullptr), nRefCnt(0)
+{
+    if (ScMatrix::IsSizeAllocatable( nC, nR))
+        pImpl = new ScMatrixImpl( nC, nR);
+    else
+        // Invalid matrix size, allocate 1x1 matrix with error value.
+        pImpl = new ScMatrixImpl( 1,1, CreateDoubleError( errStackOverflow));
 }
 
 ScMatrix::ScMatrix(SCSIZE nC, SCSIZE nR, double fInitVal) :
-    pImpl(new ScMatrixImpl(nC, nR, fInitVal)), nRefCnt(0)
+    pImpl(nullptr), nRefCnt(0)
 {
-    SAL_WARN_IF( !nC, "sc", "ScMatrix with 0 columns!");
-    SAL_WARN_IF( !nR, "sc", "ScMatrix with 0 rows!");
+    if (ScMatrix::IsSizeAllocatable( nC, nR))
+        pImpl = new ScMatrixImpl( nC, nR, fInitVal);
+    else
+        // Invalid matrix size, allocate 1x1 matrix with error value.
+        pImpl = new ScMatrixImpl( 1,1, CreateDoubleError( errStackOverflow));
 }
 
 ScMatrix::ScMatrix( size_t nC, size_t nR, const std::vector<double>& rInitVals ) :
-    pImpl(new ScMatrixImpl(nC, nR, rInitVals)), nRefCnt(0)
+    pImpl(nullptr), nRefCnt(0)
 {
-    SAL_WARN_IF( !nC, "sc", "ScMatrix with 0 columns!");
-    SAL_WARN_IF( !nR, "sc", "ScMatrix with 0 rows!");
+    if (ScMatrix::IsSizeAllocatable( nC, nR))
+        pImpl = new ScMatrixImpl( nC, nR, rInitVals);
+    else
+        // Invalid matrix size, allocate 1x1 matrix with error value.
+        pImpl = new ScMatrixImpl( 1,1, CreateDoubleError( errStackOverflow));
 }
 
 ScMatrix::~ScMatrix()
diff --git a/sc/source/filter/oox/workbookhelper.cxx b/sc/source/filter/oox/workbookhelper.cxx
index 2573a39..1ef0d1b 100644
--- a/sc/source/filter/oox/workbookhelper.cxx
+++ b/sc/source/filter/oox/workbookhelper.cxx
@@ -609,7 +609,7 @@ void WorkbookGlobals::initialize( bool bWorkbookFile )
         // #i76026# disable Undo while loading the document
         mpDoc->EnableUndo(false);
         // #i79826# disable calculating automatic row height while loading the document
-        mpDoc->EnableAdjustHeight(true);
+        mpDoc->EnableAdjustHeight(false);
         // disable automatic update of linked sheets and DDE links
         mpDoc->EnableExecuteLink(false);
 
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index 8c557af..07ebd0f 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -618,58 +618,120 @@ ScExternalRefCache::TokenArrayRef ScExternalRefCache::getCellRangeData(
             return TokenArrayRef();
         }
 
-        ScMatrixRef xMat = new ScMatrix(
-            static_cast<SCSIZE>(nDataCol2-nDataCol1+1), static_cast<SCSIZE>(nDataRow2-nDataRow1+1));
+        SCSIZE nMatrixColumns = static_cast<SCSIZE>(nDataCol2-nDataCol1+1);
+        SCSIZE nMatrixRows = static_cast<SCSIZE>(nDataRow2-nDataRow1+1);
+        ScMatrixRef xMat = new ScMatrix( nMatrixColumns, nMatrixRows);
 
-        // Only fill non-empty cells, for better performance.
+        // Needed in shrink and fill.
         vector<SCROW> aRows;
         pTab->getAllRows(aRows, nDataRow1, nDataRow2);
-        for (vector<SCROW>::const_iterator itr = aRows.begin(), itrEnd = aRows.end(); itr != itrEnd; ++itr)
+        bool bFill = true;
+
+        // Check if size could be allocated and if not skip the fill, there's
+        // one error element instead. But retry first with the actual data area
+        // if that is smaller than the original range, which works for most
+        // functions just not some that operate/compare with the original size
+        // and expect empty values in non-data areas.
+        // Restrict this though to ranges of entire columns or rows, other
+        // ranges might be on purpose. (Other special cases to handle?)
+        /* TODO: sparse matrix could help */
+        SCSIZE nMatCols, nMatRows;
+        xMat->GetDimensions( nMatCols, nMatRows);
+        if (nMatCols != nMatrixColumns || nMatRows != nMatrixRows)
         {
-            SCROW nRow = *itr;
-            vector<SCCOL> aCols;
-            pTab->getAllCols(nRow, aCols, nDataCol1, nDataCol2);
-            for (vector<SCCOL>::const_iterator itrCol = aCols.begin(), itrColEnd = aCols.end(); itrCol != itrColEnd; ++itrCol)
+            bFill = false;
+            if (aRows.empty())
             {
-                SCCOL nCol = *itrCol;
-                TokenRef pToken = pTab->getCell(nCol, nRow);
-                if (!pToken)
-                    // This should never happen!
-                    return TokenArrayRef();
-
-                SCSIZE nC = nCol - nDataCol1, nR = nRow - nDataRow1;
-                switch (pToken->GetType())
+                // There's no data at all. Set the one matrix element to empty
+                // for column-repeated and row-repeated access.
+                xMat->PutEmpty(0,0);
+            }
+            else if ((nCol1 == 0 && nCol2 == MAXCOL) || (nRow1 == 0 && nRow2 == MAXROW))
+            {
+                nDataRow1 = aRows.front();
+                nDataRow2 = aRows.back();
+                SCCOL nMinCol = std::numeric_limits<SCCOL>::max();
+                SCCOL nMaxCol = std::numeric_limits<SCCOL>::min();
+                for (vector<SCROW>::const_iterator itr = aRows.begin(), itrEnd = aRows.end(); itr != itrEnd; ++itr)
+                {
+                    vector<SCCOL> aCols;
+                    pTab->getAllCols(*itr, aCols, nDataCol1, nDataCol2);
+                    if (!aCols.empty())
+                    {
+                        nMinCol = std::min( nMinCol, aCols.front());
+                        nMaxCol = std::max( nMaxCol, aCols.back());
+                    }
+                }
+
+                if (nMinCol <= nMaxCol && ((static_cast<SCSIZE>(nMaxCol-nMinCol+1) < nMatrixColumns) ||
+                            (static_cast<SCSIZE>(nDataRow2-nDataRow1+1) < nMatrixRows)))
                 {
-                    case svDouble:
-                        xMat->PutDouble(pToken->GetDouble(), nC, nR);
-                    break;
-                    case svString:
-                        xMat->PutString(pToken->GetString(), nC, nR);
-                    break;
-                    default:
-                        ;
+                    nMatrixColumns = static_cast<SCSIZE>(nMaxCol-nMinCol+1);
+                    nMatrixRows = static_cast<SCSIZE>(nDataRow2-nDataRow1+1);
+                    xMat = new ScMatrix( nMatrixColumns, nMatrixRows);
+                    xMat->GetDimensions( nMatCols, nMatRows);
+                    if (nMatCols == nMatrixColumns && nMatRows == nMatrixRows)
+                    {
+                        nDataCol1 = nMinCol;
+                        nDataCol2 = nMaxCol;
+                        bFill = true;
+                    }
                 }
             }
         }
 
-        if (!bFirstTab)
-            pArray->AddOpCode(ocSep);
+        if (bFill)
+        {
+            // Only fill non-empty cells, for better performance.
+            for (vector<SCROW>::const_iterator itr = aRows.begin(), itrEnd = aRows.end(); itr != itrEnd; ++itr)
+            {
+                SCROW nRow = *itr;
+                vector<SCCOL> aCols;
+                pTab->getAllCols(nRow, aCols, nDataCol1, nDataCol2);
+                for (vector<SCCOL>::const_iterator itrCol = aCols.begin(), itrColEnd = aCols.end(); itrCol != itrColEnd; ++itrCol)
+                {
+                    SCCOL nCol = *itrCol;
+                    TokenRef pToken = pTab->getCell(nCol, nRow);
+                    if (!pToken)
+                        // This should never happen!
+                        return TokenArrayRef();
+
+                    SCSIZE nC = nCol - nDataCol1, nR = nRow - nDataRow1;
+                    switch (pToken->GetType())
+                    {
+                        case svDouble:
+                            xMat->PutDouble(pToken->GetDouble(), nC, nR);
+                            break;
+                        case svString:
+                            xMat->PutString(pToken->GetString(), nC, nR);
+                            break;
+                        default:
+                            ;
+                    }
+                }
+            }
 
-        ScMatrixToken aToken(xMat);
-        if (!pArray)
-            pArray.reset(new ScTokenArray);
-        pArray->AddToken(aToken);
+            if (!bFirstTab)
+                pArray->AddOpCode(ocSep);
 
-        bFirstTab = false;
+            ScMatrixToken aToken(xMat);
+            if (!pArray)
+                pArray.reset(new ScTokenArray);
+            pArray->AddToken(aToken);
 
-        if (!pNewRange)
-            pNewRange.reset(new ScRange(nDataCol1, nDataRow1, 0, nDataCol2, nDataRow2, 0));
-        else
-            pNewRange->ExtendTo(ScRange(nDataCol1, nDataRow1, 0, nDataCol2, nDataRow2, 0));
+            bFirstTab = false;
+
+            if (!pNewRange)
+                pNewRange.reset(new ScRange(nDataCol1, nDataRow1, nTab, nDataCol2, nDataRow2, nTab));
+            else
+                pNewRange->ExtendTo(ScRange(nDataCol1, nDataRow1, nTab, nDataCol2, nDataRow2, nTab));
+        }
     }
 
-    if (pNewRange)
+    rDoc.maRangeArrays.insert( RangeArrayMap::value_type(aCacheRange, pArray));
+    if (pNewRange && *pNewRange != aCacheRange)
         rDoc.maRangeArrays.insert( RangeArrayMap::value_type(*pNewRange, pArray));
+
     return pArray;
 }
 
@@ -781,37 +843,56 @@ void ScExternalRefCache::setCellRangeData(sal_uInt16 nFileId, const ScRange& rRa
             pTabData.reset(new Table);
 
         const ScMatrixRef& pMat = itrData->mpRangeData;
-        for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
+        SCSIZE nMatCols, nMatRows;
+        pMat->GetDimensions( nMatCols, nMatRows);
+        if (nMatCols > static_cast<SCSIZE>(nCol2 - nCol1) && nMatRows > static_cast<SCSIZE>(nRow2 - nRow1))
         {
-            const SCSIZE nR = nRow - nRow1;
-            for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
+            for (SCROW nRow = nRow1; nRow <= nRow2; ++nRow)
             {
-                const SCSIZE nC = nCol - nCol1;
+                const SCSIZE nR = nRow - nRow1;
+                for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
+                {
+                    const SCSIZE nC = nCol - nCol1;
 
-                ScMatrixValue value = pMat->Get(nC, nR);
+                    ScMatrixValue value = pMat->Get(nC, nR);
 
-                TokenRef pToken;
+                    TokenRef pToken;
 
-                switch (value.nType) {
-                    case SC_MATVAL_VALUE:
-                    case SC_MATVAL_BOOLEAN:
-                        pToken.reset(new formula::FormulaDoubleToken(value.fVal));
-                        break;
-                    case SC_MATVAL_STRING:
-                        pToken.reset(new formula::FormulaStringToken(value.aStr));
-                        break;
-                    default:
-                        // Don't cache empty cells.
-                        break;
-                }
+                    switch (value.nType) {
+                        case SC_MATVAL_VALUE:
+                        case SC_MATVAL_BOOLEAN:
+                            pToken.reset(new formula::FormulaDoubleToken(value.fVal));
+                            break;
+                        case SC_MATVAL_STRING:
+                            pToken.reset(new formula::FormulaStringToken(value.aStr));
+                            break;
+                        default:
+                            // Don't cache empty cells.
+                            break;
+                    }
 
-                if (pToken)
-                    // Don't mark this cell 'cached' here, for better performance.
-                    pTabData->setCell(nCol, nRow, pToken, 0, false);
+                    if (pToken)
+                        // Don't mark this cell 'cached' here, for better performance.
+                        pTabData->setCell(nCol, nRow, pToken, 0, false);
+                }
+            }
+            // Mark the whole range 'cached'.
+            pTabData->setCachedCellRange(nCol1, nRow1, nCol2, nRow2);
+        }
+        else
+        {
+            // This may happen due to a matrix not been allocated earlier, in
+            // which case it should have exactly one error element.
+            SAL_WARN("sc.ui","ScExternalRefCache::setCellRangeData - matrix size mismatch");
+            if (nMatCols != 1 || nMatRows != 1)
+                SAL_WARN("sc.ui","ScExternalRefCache::setCellRangeData - not a one element matrix");
+            else
+            {
+                sal_uInt16 nErr = GetDoubleErrorValue( pMat->GetDouble(0,0));
+                SAL_WARN("sc.ui","ScExternalRefCache::setCellRangeData - matrix error value is " << nErr <<
+                        (nErr ? ", ok" : ", not ok"));
             }
         }
-        // Mark the whole range 'cached'.
-        pTabData->setCachedCellRange(nCol1, nRow1, nCol2, nRow2);
     }
 
     size_t nTabLastId = nTabFirstId + rRange.aEnd.Tab() - rRange.aStart.Tab();
@@ -1497,63 +1578,104 @@ static ScTokenArray* convertToTokenArray(
         else
             pUsedRange.reset(new ScRange(nDataCol1, nDataRow1, 0, nDataCol2, nDataRow2, 0));
 
-        ScMatrixRef xMat = new ScMatrix(
-            static_cast<SCSIZE>(nCol2-nCol1+1), static_cast<SCSIZE>(nRow2-nRow1+1));
-
-        ScRefCellValue aCell;
-        ColumnBatch<svl::SharedString> aStringBatch(pHostDoc, pSrcDoc, CELLTYPE_STRING, CELLTYPE_EDIT);
-        ColumnBatch<double> aDoubleBatch(pHostDoc, pSrcDoc, CELLTYPE_VALUE, CELLTYPE_VALUE);
+        SCSIZE nMatrixColumns = static_cast<SCSIZE>(nCol2-nCol1+1);
+        SCSIZE nMatrixRows = static_cast<SCSIZE>(nRow2-nRow1+1);
+        ScMatrixRef xMat = new ScMatrix( nMatrixColumns, nMatrixRows);
+
+        bool bFill = true;
+        SCCOL nEffectiveCol1 = nCol1;
+        SCROW nEffectiveRow1 = nRow1;
+
+        // Check if size could be allocated and if not skip the fill, there's
+        // one error element instead. But retry first with the actual data area
+        // if that is smaller than the original range, which works for most
+        // functions just not some that operate/compare with the original size
+        // and expect empty values in non-data areas.
+        // Restrict this though to ranges of entire columns or rows, other
+        // ranges might be on purpose. (Other special cases to handle?)
+        /* TODO: sparse matrix could help */
+        SCSIZE nMatCols, nMatRows;
+        xMat->GetDimensions( nMatCols, nMatRows);
+        if (nMatCols != nMatrixColumns || nMatRows != nMatrixRows)
+        {
+            bFill = false;
+            if ((nCol1 == 0 && nCol2 == MAXCOL) || (nRow1 == 0 && nRow2 == MAXROW))
+            {
+                if ((static_cast<SCSIZE>(nDataCol2-nDataCol1+1) < nMatrixColumns) ||
+                    (static_cast<SCSIZE>(nDataRow2-nDataRow1+1) < nMatrixRows))
+                {
+                    nMatrixColumns = static_cast<SCSIZE>(nDataCol2-nDataCol1+1);
+                    nMatrixRows = static_cast<SCSIZE>(nDataRow2-nDataRow1+1);
+                    xMat = new ScMatrix( nMatrixColumns, nMatrixRows);
+                    xMat->GetDimensions( nMatCols, nMatRows);
+                    if (nMatCols == nMatrixColumns && nMatRows == nMatrixRows)
+                    {
+                        nEffectiveCol1 = nDataCol1;
+                        nEffectiveRow1 = nDataRow1;
+                        bFill = true;
+                    }
+                }
+            }
+        }
 
-        for (SCCOL nCol = nDataCol1; nCol <= nDataCol2; ++nCol)
+        if (bFill)
         {
-            const SCSIZE nC = nCol - nCol1;
-            for (SCROW nRow = nDataRow1; nRow <= nDataRow2; ++nRow)
+            ScRefCellValue aCell;
+            ColumnBatch<svl::SharedString> aStringBatch(pHostDoc, pSrcDoc, CELLTYPE_STRING, CELLTYPE_EDIT);
+            ColumnBatch<double> aDoubleBatch(pHostDoc, pSrcDoc, CELLTYPE_VALUE, CELLTYPE_VALUE);
+
+            for (SCCOL nCol = nDataCol1; nCol <= nDataCol2; ++nCol)
             {
-                const SCSIZE nR = nRow - nRow1;
+                const SCSIZE nC = nCol - nEffectiveCol1;
+                for (SCROW nRow = nDataRow1; nRow <= nDataRow2; ++nRow)
+                {
+                    const SCSIZE nR = nRow - nEffectiveRow1;
 
-                aCell.assign(*pSrcDoc, ScAddress(nCol, nRow, nTab));
+                    aCell.assign(*pSrcDoc, ScAddress(nCol, nRow, nTab));
 
-                aStringBatch.update(aCell, nC, nR, xMat);
-                aDoubleBatch.update(aCell, nC, nR, xMat);
+                    aStringBatch.update(aCell, nC, nR, xMat);
+                    aDoubleBatch.update(aCell, nC, nR, xMat);
 
-                if (aCell.hasEmptyValue())
-                    // Skip empty cells.  Matrix's default values are empty elements.
-                    continue;
+                    if (aCell.hasEmptyValue())
+                        // Skip empty cells.  Matrix's default values are empty elements.
+                        continue;
 
-                switch (aCell.meType)
-                {
-                    case CELLTYPE_FORMULA:
+                    switch (aCell.meType)
                     {
-                        ScFormulaCell* pFCell = aCell.mpFormula;
-                        sal_uInt16 nError = pFCell->GetErrCode();
-                        if (nError)
-                            xMat->PutDouble( CreateDoubleError( nError), nC, nR);
-                        else if (pFCell->IsValue())
-                        {
-                            double fVal = pFCell->GetValue();
-                            xMat->PutDouble(fVal, nC, nR);
-                        }
-                        else
-                        {
-                            svl::SharedString aStr = pFCell->GetString();
-                            aStr = pHostDoc->GetSharedStringPool().intern(aStr.getString());
-                            xMat->PutString(aStr, nC, nR);
-                        }
+                        case CELLTYPE_FORMULA:
+                            {
+                                ScFormulaCell* pFCell = aCell.mpFormula;
+                                sal_uInt16 nError = pFCell->GetErrCode();
+                                if (nError)
+                                    xMat->PutDouble( CreateDoubleError( nError), nC, nR);
+                                else if (pFCell->IsValue())
+                                {
+                                    double fVal = pFCell->GetValue();
+                                    xMat->PutDouble(fVal, nC, nR);
+                                }
+                                else
+                                {
+                                    svl::SharedString aStr = pFCell->GetString();
+                                    aStr = pHostDoc->GetSharedStringPool().intern(aStr.getString());
+                                    xMat->PutString(aStr, nC, nR);
+                                }
+                            }
+                            break;
+                            // These are handled in batch:
+                        case CELLTYPE_VALUE:
+                        case CELLTYPE_STRING:
+                        case CELLTYPE_EDIT:
+                            break;
+                        default:
+                            OSL_FAIL("attempted to convert an unknown cell type.");
                     }
-                    break;
-                    // These are handled in batch:
-                    case CELLTYPE_VALUE:
-                    case CELLTYPE_STRING:
-                    case CELLTYPE_EDIT:
-                    break;
-                    default:
-                        OSL_FAIL("attempted to convert an unknown cell type.");
                 }
-            }
 
-            aStringBatch.flush(nC, xMat);
-            aDoubleBatch.flush(nC, xMat);
+                aStringBatch.flush(nC, xMat);
+                aDoubleBatch.flush(nC, xMat);
+            }
         }
+
         if (!bFirstTab)
             pArray->AddOpCode(ocSep);
 
commit 701fa346817193d04f468f7c7657f0e4e1ccb942
Author: Michael Stahl <mstahl at redhat.com>
Date:   Sat Mar 5 00:42:05 2016 +0100

    basic: tdf#87530 if a new password is set, must set mbLoadedSource flag
    
    ... so that the library is stored (and encrypted), and not copied
    unencrypted from source storage.
    
    Change-Id: I9546087ec6f07007aa1ec377d2e959f2bae99a38
    (cherry picked from commit 6a351c5cf91d0f667168d834ba2eb5c04121c7d5)
    Reviewed-on: https://gerrit.libreoffice.org/23043
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit 2317420ecee0bf2f01f1555fdaaa56dc9fd6a9c8)

diff --git a/basic/source/uno/scriptcont.cxx b/basic/source/uno/scriptcont.cxx
index bbf1fa6..8805c38 100644
--- a/basic/source/uno/scriptcont.cxx
+++ b/basic/source/uno/scriptcont.cxx
@@ -94,6 +94,11 @@ void SfxScriptLibraryContainer::setLibraryPassword( const OUString& rLibraryName
             pImplLib->mbDoc50Password = true;
             pImplLib->mbPasswordProtected = true;
             pImplLib->maPassword = rPassword;
+            SfxScriptLibrary *const pSL(dynamic_cast<SfxScriptLibrary *>(pImplLib));
+            if (pSL && pSL->mbLoaded)
+            {
+                pSL->mbLoadedSource = true; // must store source code now!
+            }
         }
     }
     catch(const NoSuchElementException& ) {}
@@ -515,6 +520,11 @@ void SAL_CALL SfxScriptLibraryContainer::changeLibraryPassword( const OUString&
         pImplLib->mbPasswordProtected = true;
         pImplLib->mbPasswordVerified = true;
         pImplLib->maPassword = NewPassword;
+        SfxScriptLibrary *const pSL(dynamic_cast<SfxScriptLibrary *>(pImplLib));
+        if (pSL && pSL->mbLoaded)
+        {
+            pSL->mbLoadedSource = true; // must store source code now!
+        }
 
         maModifiable.setModified( true );
         pImplLib->implSetModified( true );
commit 42eaaa3ee5d14433488ac9b75204c68e47c4393e
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Mar 4 23:01:18 2016 +0100

    basic: tdf#87530 don't copy storage that doesn't exist
    
    If the Basic library is newly created it may not have been stored to the
    document storage yet.
    
    (regression from 5246fa262450f686674850c53df666422f441c86)
    
    (cherry picked from commit aeb43916366b293935314efe9454c66b4877b9d1)
    
    tdf#87530 finish the regression test
    Need to store the document twice to actually reproduce the bug.
    (cherry picked from commit 7faecc70c286c0e1a3068b77ccde771640928b37)
    
    Change-Id: I9c2fc1d7446795b9c1c2224671118b2a671dcad8
    Reviewed-on: https://gerrit.libreoffice.org/23042
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit b3f2b2529dc4ed313f423d29551577b6dfed4258)

diff --git a/basic/source/uno/namecont.cxx b/basic/source/uno/namecont.cxx
index ab47f01..c23c09e 100644
--- a/basic/source/uno/namecont.cxx
+++ b/basic/source/uno/namecont.cxx
@@ -1950,8 +1950,21 @@ void SfxLibraryContainer::storeLibraries_Impl( const uno::Reference< embed::XSto
 // fdo#68983: If there's a password and the password is not known, only
 // copying the storage works!
             // Can we simply copy the storage?
-            if (!mbOldInfoFormat && !pImplLib->isLoadedStorable() &&
-                !mbOasis2OOoFormat && xSourceLibrariesStor.is())
+            bool isCopyStorage = !mbOldInfoFormat && !mbOasis2OOoFormat
+                    && !pImplLib->isLoadedStorable()
+                    && xSourceLibrariesStor.is() /* null for user profile */;
+            if (isCopyStorage)
+            {
+                try
+                {
+                    xSourceLibrariesStor->isStorageElement(rLib.aName);
+                }
+                catch (container::NoSuchElementException const&)
+                {
+                    isCopyStorage = false;
+                }
+            }
+            if (isCopyStorage)
             {
                 try
                 {
diff --git a/sw/qa/core/macros-test.cxx b/sw/qa/core/macros-test.cxx
index 5b90d8a..b1ca97d 100644
--- a/sw/qa/core/macros-test.cxx
+++ b/sw/qa/core/macros-test.cxx
@@ -85,6 +85,7 @@ public:
 #endif
     void testFdo55289();
     void testFdo68983();
+    void testFdo87530();
     void testFindReplace();
     CPPUNIT_TEST_SUITE(SwMacrosTest);
 #if !defined(MACOSX) && !defined(WNT)
@@ -100,6 +101,7 @@ public:
 #endif
     CPPUNIT_TEST(testFdo55289);
     CPPUNIT_TEST(testFdo68983);
+    CPPUNIT_TEST(testFdo87530);
     CPPUNIT_TEST(testFindReplace);
 
     CPPUNIT_TEST_SUITE_END();
@@ -430,6 +432,90 @@ void SwMacrosTest::testFdo68983()
     xDocCloseable->close(false);
 }
 
+void SwMacrosTest::testFdo87530()
+{
+    Reference<css::lang::XComponent> xComponent =
+        loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument");
+
+    utl::TempFile aTempFile;
+    aTempFile.EnableKillingFile();
+
+    Sequence<beans::PropertyValue> desc(1);
+    desc[0].Name = "FilterName";
+    desc[0].Value <<= OUString("writer8");
+
+    {
+        // insert initial password protected library
+        Reference<document::XEmbeddedScripts> xDocScr(xComponent, UNO_QUERY_THROW);
+        Reference<script::XStorageBasedLibraryContainer> xStorBasLib(xDocScr->getBasicLibraries());
+        Reference<script::XLibraryContainer> xBasLib(xStorBasLib, UNO_QUERY_THROW);
+        Reference<script::XLibraryContainerPassword> xBasLibPwd(xStorBasLib, UNO_QUERY_THROW);
+        Reference<container::XNameContainer> xLibrary(xBasLib->createLibrary("BarLibrary"));
+        xLibrary->insertByName("BarModule",
+                uno::makeAny(OUString("Sub Main\nEnd Sub\n")));
+        xBasLibPwd->changeLibraryPassword("BarLibrary", "", "foo");
+
+        Reference<frame::XStorable> xDocStorable(xComponent, UNO_QUERY_THROW);
+        CPPUNIT_ASSERT(xDocStorable.is());
+
+        xDocStorable->storeAsURL(aTempFile.GetURL(), desc);
+    }
+
+    Reference<util::XCloseable>(xComponent, UNO_QUERY_THROW)->close(false);
+
+    // re-load
+    xComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.text.TextDocument");
+
+    {
+        // check that password-protected library survived store and re-load
+        Reference<document::XEmbeddedScripts> xDocScr(xComponent, UNO_QUERY_THROW);
+        Reference<script::XStorageBasedLibraryContainer> xStorBasLib(xDocScr->getBasicLibraries());
+        Reference<script::XLibraryContainer> xBasLib(xStorBasLib, UNO_QUERY_THROW);
+        Reference<script::XLibraryContainerPassword> xBasLibPwd(xStorBasLib, UNO_QUERY_THROW);
+        CPPUNIT_ASSERT(xBasLibPwd->isLibraryPasswordProtected("BarLibrary"));
+        CPPUNIT_ASSERT(xBasLibPwd->verifyLibraryPassword("BarLibrary", "foo"));
+        xBasLib->loadLibrary("BarLibrary");
+        CPPUNIT_ASSERT(xBasLib->isLibraryLoaded("BarLibrary"));
+        Reference<container::XNameContainer> xLibrary(xBasLib->getByName("BarLibrary"), UNO_QUERY);
+        Any module(xLibrary->getByName("BarModule"));
+        CPPUNIT_ASSERT_EQUAL(module.get<OUString>(), OUString("Sub Main\nEnd Sub\n"));
+
+        // add a second module now - tdf#87530 happened here
+        Reference<container::XNameContainer> xFooLib(xBasLib->createLibrary("FooLibrary"));
+        xFooLib->insertByName("FooModule",
+                uno::makeAny(OUString("Sub Main\nEnd Sub\n")));
+        xBasLibPwd->changeLibraryPassword("FooLibrary", "", "foo");
+
+        // store again
+        Reference<frame::XStorable> xDocStorable(xComponent, UNO_QUERY_THROW);
+        CPPUNIT_ASSERT(xDocStorable.is());
+
+        xDocStorable->store();
+    }
+
+    Reference<util::XCloseable>(xComponent, UNO_QUERY_THROW)->close(false);
+
+    // re-load
+    xComponent = loadFromDesktop(aTempFile.GetURL(), "com.sun.star.text.TextDocument");
+
+    // check that password-protected library survived store and re-load
+    Reference<document::XEmbeddedScripts> xDocScr(xComponent, UNO_QUERY_THROW);
+    Reference<script::XStorageBasedLibraryContainer> xStorBasLib(xDocScr->getBasicLibraries());
+    Reference<script::XLibraryContainer> xBasLib(xStorBasLib, UNO_QUERY_THROW);
+    Reference<script::XLibraryContainerPassword> xBasLibPwd(xStorBasLib, UNO_QUERY_THROW);
+    CPPUNIT_ASSERT(xBasLibPwd->isLibraryPasswordProtected("FooLibrary"));
+    CPPUNIT_ASSERT(xBasLibPwd->verifyLibraryPassword("FooLibrary", "foo"));
+    xBasLib->loadLibrary("FooLibrary");
+    CPPUNIT_ASSERT(xBasLib->isLibraryLoaded("FooLibrary"));
+    Reference<container::XNameContainer> xLibrary(xBasLib->getByName("FooLibrary"), UNO_QUERY);
+    Any module(xLibrary->getByName("FooModule"));
+    CPPUNIT_ASSERT_EQUAL(module.get<OUString>(), OUString("Sub Main\nEnd Sub\n"));
+
+    // close
+    Reference<util::XCloseable>(xComponent, UNO_QUERY_THROW)->close(false);
+}
+
+
 void SwMacrosTest::testFindReplace()
 {
     // we need a full document with view and layout etc. because ::GetNode()
commit 31313fbb42a2c49fc4e3c6d1cedbff6b82138b95
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon Mar 7 09:52:51 2016 +0000

    upgrade neon to 0.30.1
    
    Reviewed-on: https://gerrit.libreoffice.org/22977
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit 1827987fd11cd726005977e49d001283033f0419)
    
    Change-Id: If84ce83cdbde530f7a6743c93ae210b030a41c30
    Reviewed-on: https://gerrit.libreoffice.org/23001
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Michael Stahl <mstahl at redhat.com>
    (cherry picked from commit e6a8fb33a948adf367baca31d54e1eb2f3ff0dc4)

diff --git a/download.lst b/download.lst
index 332df86..ca93af8 100644
--- a/download.lst
+++ b/download.lst
@@ -100,7 +100,7 @@ export MWAW_VERSION_MICRO := 5
 export MWAW_TARBALL := libmwaw-0.3.$(MWAW_VERSION_MICRO).tar.bz2
 export MYSQLCPPCONN_TARBALL := 7239a4430efd4d0189c4f24df67f08e5-mysql-connector-c++-1.1.4.tar.gz
 export MYTHES_TARBALL := a8c2c5b8f09e7ede322d5c602ff6a4b6-mythes-1.2.4.tar.gz
-export NEON_TARBALL := ff369e69ef0f0143beb5626164e87ae2-neon-0.29.5.tar.gz
+export NEON_TARBALL := 231adebe5c2f78fded3e3df6e958878e-neon-0.30.1.tar.gz
 export NSS_TARBALL := 478e0e90ebc4a90159549e77021021fd-nss-3.19.4-with-nspr-4.10.10.tar.gz
 export ODFGEN_MD5SUM := 8716be5c22ae8353f9aaa380d74840dc
 export ODFGEN_VERSION_MICRO := 4
diff --git a/external/neon/neon.patch b/external/neon/neon.patch
index de52043..5abc3c9 100644
--- a/external/neon/neon.patch
+++ b/external/neon/neon.patch
@@ -319,51 +319,10 @@
  /*   3x */ DG, DG, DG, DG, DG, DG, DG, DG, DG, DG, CL, SD, OT, SD, OT, QU,
  /*   4x */ AT, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL,
  /*   5x */ AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, AL, GD, OT, GD, OT, US,
---- src/ne_utils.c	2006-03-07 10:36:43.000000000 +0100
-+++ src/ne_utils.c	2011-02-03 10:26:21.000000000 +0100
-@@ -118,6 +118,9 @@
- #ifdef HAVE_GNUTLS
-     ", GNU TLS " LIBGNUTLS_VERSION
- #endif /* HAVE_GNUTLS */
-+#ifdef HAVE_SSPI
-+    ", SSPI"
-+#endif /* HAVE_SSPI */
-    "."
- ;
- 
-@@ -137,7 +140,7 @@
-     switch (feature) {
- #if defined(NE_HAVE_SSL) || defined(NE_HAVE_ZLIB) || defined(NE_HAVE_IPV6) \
-     || defined(NE_HAVE_SOCKS) || defined(NE_HAVE_LFS) \
--    || defined(NE_HAVE_TS_SSL) || defined(NE_HAVE_I18N)
-+    || defined(NE_HAVE_TS_SSL) || defined(NE_HAVE_I18N) || defined(HAVE_SSPI)
- #ifdef NE_HAVE_SSL
-     case NE_FEATURE_SSL:
- #endif
-@@ -159,6 +162,9 @@
- #ifdef NE_HAVE_I18N
-     case NE_FEATURE_I18N:
- #endif
-+#ifdef HAVE_SSPI
-+    case NE_FEATURE_SSPI:
-+#endif
-         return 1;
- #endif /* NE_HAVE_* */
-     default:
---- src/ne_utils.h	2007-07-16 08:54:57.000000000 +0200
-+++ src/ne_utils.h	2011-02-03 10:26:21.000000000 +0100
-@@ -54,6 +54,7 @@
- #define NE_FEATURE_SOCKS (5) /* SOCKSv5 support */
- #define NE_FEATURE_TS_SSL (6) /* Thread-safe SSL/TLS support */
- #define NE_FEATURE_I18N (7) /* i18n error message support */
-+#define NE_FEATURE_SSPI (8) /* NTLM/Negotiate authentication protocol via SSPI */
- 
- /* Returns non-zero if library is built with support for the given
-  * NE_FEATURE_* feature code 'code'. */
 --- src/ne_openssl.c
 +++ src/ne_openssl.c
-@@ -41,6 +41,13 @@
- #include <pthread.h>
+@@ -43,6 +43,13 @@
+ #endif
  #endif
  
 +#ifdef WIN32
@@ -376,7 +335,7 @@
  #include "ne_ssl.h"
  #include "ne_string.h"
  #include "ne_session.h"
-@@ -798,6 +798,31 @@
+@@ -798,6 +805,31 @@
      X509_STORE_load_locations(store, NE_SSL_CA_BUNDLE, NULL);
  #else
      X509_STORE_set_default_paths(store);
diff --git a/external/neon/neon_ne_set_request_flag.patch b/external/neon/neon_ne_set_request_flag.patch
index 3bcafd6..5189406 100644
--- a/external/neon/neon_ne_set_request_flag.patch
+++ b/external/neon/neon_ne_set_request_flag.patch
@@ -1,11 +1,11 @@
 --- src/ne_request.c	2010-09-28 13:57:26.000000000 +0200
 +++ src/ne_request.c	2011-05-18 12:39:05.134445529 +0200
-@@ -529,7 +529,7 @@
+@@ -585,7 +585,7 @@
  
  void ne_set_request_flag(ne_request *req, ne_request_flag flag, int value)
  {
--    if (flag < NE_SESSFLAG_LAST) {
-+    if (flag < NE_REQFLAG_LAST) {
+-    if (flag < (ne_request_flag)NE_SESSFLAG_LAST) {
++    if (flag < (ne_request_flag)NE_REQFLAG_LAST) {
          req->flags[flag] = value;
      }
  }


More information about the Libreoffice-commits mailing list