sc/source/filter/orcus/orcusfiltersimpl.cxx | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
New commits: commit e38d4e8cf2b1a1b5c146acbe325d31f84da676b0 Author: Kohei Yoshida <kohei.yosh...@collabora.com> AuthorDate: Fri Jul 11 17:50:31 2025 -0400 Commit: Kohei Yoshida <kohei.yosh...@collabora.com> CommitDate: Sat Jul 12 03:56:15 2025 +0200 Write the content of medium being loaded to temp file This will hopefully avoid unnecessary memory spike when loading a large file, by not loading the entire content of the file to an in-memory buffer. Change-Id: Ia46527f0835f8ddc7f67f26e36b289c4e9d66eed Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187760 Reviewed-by: Kohei Yoshida <ko...@libreoffice.org> Tested-by: Jenkins diff --git a/sc/source/filter/orcus/orcusfiltersimpl.cxx b/sc/source/filter/orcus/orcusfiltersimpl.cxx index 7f16a01bfe22..8ea4faebf9c6 100644 --- a/sc/source/filter/orcus/orcusfiltersimpl.cxx +++ b/sc/source/filter/orcus/orcusfiltersimpl.cxx @@ -18,6 +18,7 @@ #include <svl/itemset.hxx> #include <rtl/ustring.hxx> #include <sal/log.hxx> +#include <unotools/tempfile.hxx> #include <orcus/format_detection.hpp> #include <orcus/orcus_import_ods.hpp> @@ -40,21 +41,30 @@ uno::Reference<task::XStatusIndicator> getStatusIndicator(const SfxMedium& rMedi bool loadFileContent(SfxMedium& rMedium, orcus::iface::import_filter& filter) { - SvStream* pStream = rMedium.GetInStream(); - pStream->Seek(0); - static const size_t nReadBuffer = 1024 * 32; - OStringBuffer aBuffer((int(nReadBuffer))); - size_t nRead = 0; + // write the content to a temp file + utl::TempFileNamed aTemp; + aTemp.EnableKillingFile(); + SvStream* pDest = aTemp.GetStream(StreamMode::WRITE); + + SvStream* pSrc = rMedium.GetInStream(); + pSrc->Seek(0); + const std::size_t nReadBuffer = 1024 * 32; + std::size_t nRead = 0; + do { char pData[nReadBuffer]; - nRead = pStream->ReadBytes(pData, nReadBuffer); - aBuffer.append(pData, nRead); + nRead = pSrc->ReadBytes(pData, nReadBuffer); + pDest->WriteBytes(pData, nRead); } while (nRead == nReadBuffer); + aTemp.CloseStream(); + try { - filter.read_stream(aBuffer); + // memory-map the temp file and start the import + orcus::file_content input(aTemp.GetFileName().toUtf8()); + filter.read_stream(input.str()); } catch (const std::exception& e) {