Stephan Bergmann 495918adb9 Fix heap-use-after-free in ScOutputData::FindChanged
The loop in ScOutputData::FindChanged reused the ScFormulaCell pointers cached
in mpRowInfo.  But the preceding EnsureFormulaCellResults call can contract
an auto-resizing matrix formula, and can thus delete the matrix's cells.

This apparently started to break in 8070124eb9f0f5a4c7ea26a0fe39366d2ff8d26a
"sc: fix crash when a matrix formula contracts mid-iteration", making the
CppunitTest_sc_uicalc2 it introduced fail with

> ==558773==ERROR: AddressSanitizer: heap-use-after-free on address 0x7ca7f493fc48 at pc 0x7bc78ec4338a bp 0x7ffdce34e080 sp 0x7ffdce34e078
> READ of size 8 at 0x7ca7f493fc48 thread T0
>  #0 in ScFormulaCell::IsRunning() const at engine/sc/inc/formulacell.hxx:363:48
>  #1 in ScOutputData::FindChanged() at engine/sc/source/ui/view/output.cxx:1963:29
>  #2 in ScGridWindow::UpdateFormulaRange(short, int, short, int) at engine/sc/source/ui/view/gridwin.cxx:5388:17
>  #3 in ScGridWindow::UpdateFormulas(short, int, short, int) at engine/sc/source/ui/view/gridwin.cxx:5336:5
>  #4 in ScTabView::UpdateFormulas(short, int, short, int) at engine/sc/source/ui/view/tabview3.cxx:2785:26
>  #5 in ScTabViewShell::Notify(SfxBroadcaster&, SfxHint const&) at engine/sc/source/ui/view/tabvwsh5.cxx:242:17
>  #6 in SfxBroadcaster::Broadcast(SfxHint const&) at engine/svl/source/notify/SfxBroadcaster.cxx:43:24
>  #7 in ScDocShell::PostDataChanged() at engine/sc/source/ui/docshell/docsh3.cxx:95:5
>  #8 in ScDocShell::SetDocumentModified() at engine/sc/source/ui/docshell/docsh.cxx:3265:9
>  #9 in ScDocShellModificator::SetDocumentModified() at engine/sc/source/ui/docshell/docsh.cxx:3656:19
>  #10 in (anonymous namespace)::performAutoFormatAndUpdate(std::basic_string_view<char16_t, std::char_traits<char16_t>>, ScMarkData const&, short, int, short, bool, bool, std::shared_ptr<ScDocShellModificator> const&, ScViewFunc&) at engine/sc/source/ui/view/viewfunc.cxx:478:19
>  #11 in ScViewFunc::EnterData(short, int, short, rtl::OUString const&, EditTextObject const*, bool) at engine/sc/source/ui/view/viewfunc.cxx:817:9
>  #12 in ScViewFunc::EnterDataToCurrentCell(rtl::OUString const&, EditTextObject const*, bool) at engine/sc/source/ui/view/viewfunc.cxx:665:5
>  #13 in ScCellShell::Execute(SfxRequest&) at engine/sc/source/ui/view/cellsh3.cxx:290:40
>  #14 in SfxStubScCellShellExecute(SfxShell*, SfxRequest&) at engine/workdir/SdiTarget/sc/sdi/scslots.hxx:7965:27
>  #15 in SfxDispatcher::Call_Impl(SfxShell&, SfxSlot const&, SfxRequest&, bool) at engine/sfx2/source/control/dispatch.cxx:256:9
>  #16 in SfxDispatcher::Execute_(SfxShell&, SfxSlot const&, SfxRequest&, SfxCallMode) at engine/sfx2/source/control/dispatch.cxx:755:9
>  #17 in SfxBindings::Execute_Impl(SfxRequest&, SfxSlot const*, SfxShell*) at engine/sfx2/source/control/bindings.cxx:1054:22
>  #18 in SfxBindings::Execute_Impl(unsigned short, SfxPoolItem const**, SfxCallMode) at engine/sfx2/source/control/bindings.cxx:961:5
>  #19 in SfxBindings::Execute(unsigned short, SfxPoolItem const**, SfxCallMode) at engine/sfx2/source/control/bindings.cxx:884:12
>  #20 in ScCellShell::Execute(SfxRequest&) at engine/sc/source/ui/view/cellsh3.cxx:381:39
>  #21 in SfxStubScCellShellExecute(SfxShell*, SfxRequest&) at engine/workdir/SdiTarget/sc/sdi/scslots.hxx:7965:27
>  #22 in SfxDispatcher::Call_Impl(SfxShell&, SfxSlot const&, SfxRequest&, bool) at engine/sfx2/source/control/dispatch.cxx:256:9
>  #23 in SfxDispatcher::Execute_(SfxShell&, SfxSlot const&, SfxRequest&, SfxCallMode) at engine/sfx2/source/control/dispatch.cxx:755:9
>  #24 in SfxBindings::Execute_Impl(SfxRequest&, SfxSlot const*, SfxShell*) at engine/sfx2/source/control/bindings.cxx:1054:22
>  #25 in SfxBindings::Execute_Impl(unsigned short, SfxPoolItem const**, SfxCallMode) at engine/sfx2/source/control/bindings.cxx:961:5
>  #26 in SfxBindings::Execute(unsigned short, SfxPoolItem const**, SfxCallMode) at engine/sfx2/source/control/bindings.cxx:884:12
>  #27 in ScInputHandler::EnterHandler2(ScEnterMode, bool, rtl::OUString, rtl::OUString const&) at engine/sc/source/ui/app/inputhdl.cxx:3537:23
>  #28 in ScInputHandler::EnterHandler(ScEnterMode, bool) at engine/sc/source/ui/app/inputhdl.cxx:3264:5
>  #29 in ScModule::InputEnterHandler(ScEnterMode, bool) at engine/sc/source/ui/app/scmod.cxx:1473:19
>  #30 in ScTabViewShell::TabKeyInput(KeyEvent const&) at engine/sc/source/ui/view/tabvwsh4.cxx:1469:33
>  #31 in ScGridWindow::KeyInput(KeyEvent const&) at engine/sc/source/ui/view/gridwin.cxx:3945:26
>  #32 in (anonymous namespace)::KitPostAsyncEvent(void*, void*) at engine/sfx2/source/view/kithelper.cxx:1298:35
>  #33 in Link<void*, void>::Call(void*) const at engine/include/tools/link.hxx:105:45
>  #34 in ImplHandleUserEvent(ImplSVEvent*) at engine/vcl/source/window/winproc.cxx:2311:30
>  #35 in ImplWindowFrameProc(vcl::Window*, SalEvent, void const*) at engine/vcl/source/window/winproc.cxx:2868:13
>  #36 in SalFrame::CallCallback(SalEvent, void const*) const at engine/vcl/inc/salframe.hxx:310:29
>  #37 in SvpSalInstance::ProcessEvent(SalUserEventList::SalUserEvent) at engine/vcl/headless/svpinst.cxx:289:22
>  #38 in non-virtual thunk to SvpSalInstance::ProcessEvent(SalUserEventList::SalUserEvent) at engine/vcl/headless/svpinst.cxx
>  #39 in SalUserEventList::DispatchUserEvents(bool)::$_0::operator()() const at engine/vcl/source/app/salusereventlist.cxx:119:58
>  #40 in SalUserEventList::DispatchUserEvents(bool) at engine/vcl/source/app/salusereventlist.cxx:120:13
>  #41 in SvpSalInstance::ImplYield(bool, bool) at engine/vcl/headless/svpinst.cxx:442:22
>  #42 in SvpSalInstance::DoYield(bool, bool) at engine/vcl/headless/svpinst.cxx:519:21
>  #43 in InnerYield(bool, bool) at engine/vcl/source/app/svapp.cxx:389:48
>  #44 in Scheduler::ProcessEventsToIdle() at engine/vcl/source/app/svapp.cxx:449:12
>  #45 in ScModelTestBase::insertStringToCell(rtl::OUString const&, std::basic_string_view<char16_t, std::char_traits<char16_t>>) at engine/sc/qa/unit/helper/qahelper.cxx:318:5
>  #46 in testSpillMatrixContractionOnEdit::TestBody() at engine/sc/qa/unit/uicalc/uicalc2.cxx:2184:5
>
> 0x7ca7f493fc48 is located 72 bytes inside of 160-byte region [0x7ca7f493fc00,0x7ca7f493fca0)
> freed by thread T0 here:
>  #0 in operator delete(void*, unsigned long) at ~/github.com/llvm/llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:187:3
>  #1 in std::default_delete<ScFormulaCell>::operator()(ScFormulaCell*) const at ~/gcc/inst/lib/gcc/x86_64-pc-linux-gnu/17.0.0/../../../../include/c++/17.0.0/bits/unique_ptr.h:92:2
>  #2 in std::default_delete<ScFormulaCell> std::for_each<__gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<ScFormulaCell**, std::__cxx1998::vector<ScFormulaCell*, std::allocator<ScFormulaCell*>>>, std::__debug::vector<ScFormulaCell*, std::allocator<ScFormulaCell*>>, std::random_access_iterator_tag>, std::default_delete<ScFormulaCell>>(__gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<ScFormulaCell**, std::__cxx1998::vector<ScFormulaCell*, std::allocator<ScFormulaCell*>>>, std::__debug::vector<ScFormulaCell*, std::allocator<ScFormulaCell*>>, std::random_access_iterator_tag>, __gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<ScFormulaCell**, std::__cxx1998::vector<ScFormulaCell*, std::allocator<ScFormulaCell*>>>, std::__debug::vector<ScFormulaCell*, std::allocator<ScFormulaCell*>>, std::random_access_iterator_tag>, std::default_delete<ScFormulaCell>) at ~/gcc/inst/lib/gcc/x86_64-pc-linux-gnu/17.0.0/../../../../include/c++/17.0.0/bits/stl_algo.h:3775:2
>  #3 in mdds::mtv::noncopyable_managed_element_block<54, ScFormulaCell, mdds::mtv::delayed_delete_vector>::overwrite_values(mdds::mtv::base_element_block&, unsigned long, unsigned long) at engine/workdir/UnpackedTarball/mdds/include/mdds/multi_type_vector/soa/../types.hpp:779:9
>  #4 in void std::__invoke_impl<void, void (*&)(mdds::mtv::base_element_block&, unsigned long, unsigned long), mdds::mtv::base_element_block&, unsigned long, unsigned long>(std::__invoke_other, void (*&)(mdds::mtv::base_element_block&, unsigned long, unsigned long), mdds::mtv::base_element_block&, unsigned long&&, unsigned long&&) at ~/gcc/inst/lib/gcc/x86_64-pc-linux-gnu/17.0.0/../../../../include/c++/17.0.0/bits/invoke.h:63:14
>  #5 in std::enable_if<is_invocable_r_v<void, void (*&)(mdds::mtv::base_element_block&, unsigned long, unsigned long), mdds::mtv::base_element_block&, unsigned long, unsigned long>, void>::type std::__invoke_r<void, void (*&)(mdds::mtv::base_element_block&, unsigned long, unsigned long), mdds::mtv::base_element_block&, unsigned long, unsigned long>(void (*&)(mdds::mtv::base_element_block&, unsigned long, unsigned long), mdds::mtv::base_element_block&, unsigned long&&, unsigned long&&) at ~/gcc/inst/lib/gcc/x86_64-pc-linux-gnu/17.0.0/../../../../include/c++/17.0.0/bits/invoke.h:113:2
>  #6 in std::_Function_handler<void (mdds::mtv::base_element_block&, unsigned long, unsigned long), void (*)(mdds::mtv::base_element_block&, unsigned long, unsigned long)>::_M_invoke(std::_Any_data const&, mdds::mtv::base_element_block&, unsigned long&&, unsigned long&&) at ~/gcc/inst/lib/gcc/x86_64-pc-linux-gnu/17.0.0/../../../../include/c++/17.0.0/bits/std_function.h:295:9
>  #7 in std::function<void (mdds::mtv::base_element_block&, unsigned long, unsigned long)>::operator()(mdds::mtv::base_element_block&, unsigned long, unsigned long) const at ~/gcc/inst/lib/gcc/x86_64-pc-linux-gnu/17.0.0/../../../../include/c++/17.0.0/bits/std_function.h:581:9
>  #8 in mdds::mtv::element_block_funcs<mdds::mtv::default_element_block<10, double, mdds::mtv::delayed_delete_vector>, mdds::mtv::default_element_block<52, svl::SharedString, mdds::mtv::delayed_delete_vector>, mdds::mtv::noncopyable_managed_element_block<53, EditTextObject, mdds::mtv::delayed_delete_vector>, mdds::mtv::noncopyable_managed_element_block<54, ScFormulaCell, mdds::mtv::delayed_delete_vector>>::overwrite_values(mdds::mtv::base_element_block&, unsigned long, unsigned long) at engine/workdir/UnpackedTarball/mdds/include/mdds/multi_type_vector/soa/.././block_funcs.hpp:209:9
>  #9 in mdds::mtv::soa::multi_type_vector<sc::CellStoreTraits>::set_empty_in_single_block(unsigned long, unsigned long, unsigned long, bool) at engine/workdir/UnpackedTarball/mdds/include/mdds/multi_type_vector/soa/main_def.inl:1976:13
>  #10 in mdds::mtv::soa::multi_type_vector<sc::CellStoreTraits>::set_empty_impl(unsigned long, unsigned long, unsigned long, bool) at engine/workdir/UnpackedTarball/mdds/include/mdds/multi_type_vector/soa/main_def.inl:1898:18
>  #11 in mdds::mtv::soa::multi_type_vector<sc::CellStoreTraits>::set_empty(mdds::mtv::soa::detail::iterator_base<mdds::mtv::soa::multi_type_vector<sc::CellStoreTraits>::iterator_trait> const&, unsigned long, unsigned long) at engine/workdir/UnpackedTarball/mdds/include/mdds/multi_type_vector/soa/main_def.inl:1142:12
>  #12 in (anonymous namespace)::EmptyCells::operator()(sc::RowSpan const&) at engine/sc/source/core/data/column3.cxx:1066:34
>  #13 in (anonymous namespace)::EmptyCells std::for_each<std::reverse_iterator<__gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<sc::RowSpan*, std::__cxx1998::vector<sc::RowSpan, std::allocator<sc::RowSpan>>>, std::__debug::vector<sc::RowSpan, std::allocator<sc::RowSpan>>, std::random_access_iterator_tag>>, (anonymous namespace)::EmptyCells>(std::reverse_iterator<__gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<sc::RowSpan*, std::__cxx1998::vector<sc::RowSpan, std::allocator<sc::RowSpan>>>, std::__debug::vector<sc::RowSpan, std::allocator<sc::RowSpan>>, std::random_access_iterator_tag>>, std::reverse_iterator<__gnu_debug::_Safe_iterator<__gnu_cxx::__normal_iterator<sc::RowSpan*, std::__cxx1998::vector<sc::RowSpan, std::allocator<sc::RowSpan>>>, std::__debug::vector<sc::RowSpan, std::allocator<sc::RowSpan>>, std::random_access_iterator_tag>>, (anonymous namespace)::EmptyCells) at ~/gcc/inst/lib/gcc/x86_64-pc-linux-gnu/17.0.0/../../../../include/c++/17.0.0/bits/stl_algo.h:3775:2
>  #14 in ScColumn::DeleteCells(sc::ColumnBlockPosition&, int, int, InsertDeleteFlags) at engine/sc/source/core/data/column3.cxx:1096:5
>  #15 in ScColumn::DeleteArea(int, int, InsertDeleteFlags, bool, sc::ColumnSpanSet*) at engine/sc/source/core/data/column3.cxx:1120:19
>  #16 in ScTable::DeleteArea(short, int, short, int, InsertDeleteFlags, bool, sc::ColumnSpanSet*) at engine/sc/source/core/data/table2.cxx:433:25
>  #17 in ScDocument::DeleteAreaTab(short, int, short, int, short, InsertDeleteFlags) at engine/sc/source/core/data/document.cxx:2064:17
>  #18 in ScDocument::ResizeMatrixFormula(ScAddress const&, short, int) at engine/sc/source/core/data/documen4.cxx:517:17
>  #19 in ScDocument::ProcessPendingMatrixResizes() at engine/sc/source/core/data/documen4.cxx:623:9
>  #20 in sc::MatrixResizeGuard::~MatrixResizeGuard() at engine/sc/inc/MatrixResizeGuard.hxx:39:19
>  #21 in ScColumn::EnsureFormulaCellResults(int, int, bool) at engine/sc/source/core/data/column4.cxx:2012:1
>  #22 in ScTable::EnsureFormulaCellResults(short, int, short, int, bool) at engine/sc/source/core/data/table7.cxx:449:32
>  #23 in ScDocument::EnsureFormulaCellResults(ScRange const&, bool) at engine/sc/source/core/data/document10.cxx:1037:27
>  #24 in ScOutputData::FindChanged() at engine/sc/source/ui/view/output.cxx:1950:20
>  #25 in ScGridWindow::UpdateFormulaRange(short, int, short, int) at engine/sc/source/ui/view/gridwin.cxx:5388:17

Signed-off-by: Stephan Bergmann <stephan.bergmann@collabora.com>
Change-Id: I0e32afb07a49f149294e2bf20cb10194ae84fd81
Reviewed-on: https://gerrit.collaboraoffice.com/c/online/+/4135
Reviewed-by: Noel Grandin <noel.grandin@collabora.com>
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
(cherry picked from commit 780c73802eb8ace937d7b0d5be8a33ba710d2f55)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/206646
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
2026-06-16 11:04:21 +02:00
2025-05-30 11:22:32 +02:00
2026-03-29 09:46:56 +02:00
2026-03-29 09:46:56 +02:00
2026-06-04 10:00:29 +02:00
2026-05-06 08:50:02 +02:00
2026-06-03 20:17:35 +02:00
2026-06-09 14:49:09 +02:00
2026-06-13 20:55:34 +02:00
2026-06-15 17:09:18 +02:00
2025-12-07 12:54:23 +01:00
2026-05-25 16:27:56 +02:00
2026-03-04 12:37:18 +01:00
2026-06-15 22:45:57 +02:00
…
2026-06-01 22:16:56 +02:00
2026-06-08 10:09:40 +02:00
2026-03-29 09:44:50 +02:00
2026-06-10 22:28:40 +02:00
2026-06-04 10:00:29 +02:00
2026-06-01 20:44:45 +02:00
2026-03-04 11:29:39 +01:00
2026-06-04 10:00:29 +02:00
2026-06-05 12:42:59 +02:00
2026-06-16 09:18:32 +02:00
2026-05-22 09:32:38 +02:00
2026-06-11 10:36:59 +02:00
2026-02-18 21:17:13 +01:00
2026-06-16 00:45:38 +02:00
2026-05-17 19:26:13 +02:00
2026-03-16 14:58:18 +01:00
…
2026-06-13 17:20:07 +02:00
2011-01-11 21:49:39 +00:00
…
2026-06-16 01:21:10 +02:00
2025-08-06 18:36:42 +02:00
2026-04-21 14:52:28 +02:00
2026-04-30 10:39:37 +02:00
2018-10-16 14:29:06 +02:00

LibreOffice

Coverity Scan Build Status OpenSSF Best Practices Translation status

LibreOffice is an integrated office suite based on copyleft licenses and compatible with most document formats and standards. Libreoffice is backed by The Document Foundation, which represents a large independent community of enterprises, developers and other volunteers moved by the common goal of bringing to the market the best software for personal productivity. LibreOffice is open source, and free to download, use and distribute.

A quick overview of the LibreOffice code structure.

Overview

You can develop for LibreOffice in one of two ways, one recommended and one much less so. First the somewhat less recommended way: it is possible to use the SDK to develop an extension, for which you can read the API docs and Developers Guide. This re-uses the (extremely generic) UNO APIs that are also used by macro scripting in StarBasic.

The best way to add a generally useful feature to LibreOffice is to work on the code base however. Overall this way makes it easier to compile and build your code, it avoids any arbitrary limitations of our scripting APIs, and in general is far more simple and intuitive - if you are a reasonably able C++ programmer.

The Build Chain and Runtime Baselines

These are the current minimal operating system and compiler versions to run and compile LibreOffice, also used by the TDF builds:

  • Windows:
  • macOS:
    • Runtime: 11
    • Build: 13 or later + Xcode 14.3 or later (using latest version available for a given version of macOS)
  • Linux:
    • Runtime: RHEL 9 or CentOS 9 and comparable
    • Build: either GCC 13; or Clang 18 with libstdc++ 11
  • iOS (only for LibreOfficeKit):
    • Runtime: 14.5 (only support for newer i devices == 64 bit)
    • Build: Xcode 12.5 and iPhone SDK 14.5
  • Android:
    • Build: NDK 27 and SDK 30.0.3
  • Emscripten / WASM:
    • Runtime: a browser with SharedMemory support (threads + atomics)
    • Build: Qt 5.15 with Qt supported Emscripten 1.39.8
    • See README.wasm

Java is required for building many parts of LibreOffice. In TDF Wiki article Development/Java, the exact modules that depend on Java are listed.

The baseline for Java is Java Development Kit (JDK) Version 17 or later.

The baseline for Python is version 3.11. It follows the version available in SUSE Linux Enterprise Desktop and the Maintenance Support version of Red Hat Enterprise Linux.

If you want to use Clang with the LibreOffice compiler plugins, the minimal version of Clang is 18. Since Xcode doesn't provide the compiler plugin headers, you have to compile your own Clang to use them on macOS.

You can find the TDF configure switches in the distro-configs/ directory.

To setup your initial build environment on Windows and macOS, we provide the LibreOffice Development Environment (LODE) scripts.

For more information see the build instructions for your platform in the TDF wiki.

The Important Bits of Code

Each module should have a README.md file inside it which has some degree of documentation for that module; patches are most welcome to improve those. We have those turned into a web page here:

https://docs.libreoffice.org/

However, there are two hundred modules, many of them of only peripheral interest for a specialist audience. So - where is the good stuff, the code that is most useful. Here is a quick overview of the most important ones:

Module Description
sal/ this provides a simple System Abstraction Layer
tools/ this provides basic internal types: Rectangle, Color etc.
vcl/ this is the widget toolkit library and one rendering abstraction
framework/ UNO framework, responsible for building toolbars, menus, status bars, and the chrome around the document using widgets from VCL, and XML descriptions from /uiconfig/ files
sfx2/ legacy core framework used by Writer/Calc/Draw: document model / load/save / signals for actions etc.
svx/ drawing model related helper code, including much of Draw/Impress

Then applications

Module Description
desktop/ this is where the main() for the application lives, init / bootstrap. the name dates back to an ancient StarOffice that also drew a desktop
sw/ Writer
sc/ Calc
sd/ Draw / Impress

There are several other libraries that are helpful from a graphical perspective:

Module Description
basegfx/ algorithms and data-types for graphics as used in the canvas
canvas/ new (UNO) canvas rendering model with various backends
cppcanvas/ C++ helper classes for using the UNO canvas
drawinglayer/ View code to render drawable objects and break them down into primitives we can render more easily.

Rules for #include Directives (C/C++)

Use the "..." form if and only if the included file is found next to the including file. Otherwise, use the <...> form. (For further details, see the mail Re: C[++]: Normalizing include syntax ("" vs <>).)

The UNO API include files should consistently use double quotes, for the benefit of external users of this API.

loplugin:includeform (compilerplugins/clang/includeform.cxx) enforces these rules.

Finding Out More

Beyond this, you can read the README.md files, send us patches, ask on the mailing list libreoffice@lists.freedesktop.org (no subscription required) or poke people on IRC #libreoffice-dev on irc.libera.chat - we're a friendly and generally helpful mob. We know the code can be hard to get into at first, and so there are no silly questions.

SAST Tools

PVS-Studio - static analyzer for C, C++, C#, and Java code.

S
Description
Dépôt d'ODFStudio
Readme
2.1 GiB
Languages
C++ 82.6%
Java 5.1%
Rich Text Format 2.3%
Python 2%
PostScript 1.9%
Other 5.6%