Bug 158862 - LibreOffice crashes when attempting to inspect a UNO object in the Watch Window during debugging after successful initial inspection.
Summary: LibreOffice crashes when attempting to inspect a UNO object in the Watch Wind...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
7.6.4.1 release
Hardware: x86-64 (AMD64) All
: medium normal
Assignee: Mike Kaganski
URL:
Whiteboard: target:24.8.0 target:24.2.0.2
Keywords: haveBacktrace
Depends on:
Blocks:
 
Reported: 2023-12-26 07:36 UTC by Henrry John
Modified: 2024-01-05 07:26 UTC (History)
0 users

See Also:
Crash report or crash signature:


Attachments
gdb bt (19.93 KB, text/plain)
2023-12-26 15:32 UTC, Julien Nabet
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Henrry John 2023-12-26 07:36:25 UTC
Description:
After successfully running the provided Basic subroutine, the LibreOffice application allows for the initial inspection of the UNO object (textDoc) in the Watch Window. The variable `textDoc`, its value, and type ("com.sun.star.text.TextDocument") are visible. However, attempting to perform a deeper inspection, either by double-clicking the variable or clicking the drop-down option, results in a consistent crash of LibreOffice. The crash occurs specifically during attempts to inspect the variable further. The issue persists even after restarting LibreOffice, resetting the user profile, and running in Safe Mode.

Steps to Reproduce:
1.Open LibreOffice and create a new Basic module.
2.Add the following Basic subroutine:
`Sub Example
    Dim textDoc As Object : textDoc = CreateUnoService("com.sun.star.text.TextDocument")
End Sub`
3.Compile and execute the subroutine successfully.
4. Set a breakpoint at the `End Sub` line.
5. Debug the subroutine and observe the `textDoc` object in the Watch Window.
6. Double-click the `textDoc` variable or click the drop-down option to inspect the `textDoc` object further.

Actual Results:
LibreOffice allows for the initial inspection of the `textDoc` object in the Watch Window, displaying the variable's value and type. However, attempting to perform a deeper inspection by double-clicking the variable or clicking the drop-down option results in a crash of LibreOffice.

Expected Results:
The Watch Window should allow both initial and deeper inspection of the `textDoc` object without causing LibreOffice to crash.


Reproducible: Always


User Profile Reset: Yes

Additional Info:
Version: 7.6.4.1 (X86_64) / LibreOffice Community
Build ID: e19e193f88cd6c0525a17fb7a176ed8e6a3e2aa1
CPU threads: 20; OS: Windows 10.0 Build 22621; UI render: Skia/Raster; VCL: win
Locale: en-GB (en_US); UI: en-GB
Calc: CL threaded
Comment 1 Mike Kaganski 2023-12-26 09:23:40 UTC Comment hidden (obsolete)
Comment 2 Mike Kaganski 2023-12-26 09:24:28 UTC
(In reply to Henrry John from comment #0)
> 2.Add the following Basic subroutine:
> `Sub Example
>     Dim textDoc As Object : textDoc =
> CreateUnoService("com.sun.star.text.TextDocument")
> End Sub`

Sorry, I see it.
Comment 3 Mike Kaganski 2023-12-26 09:26:49 UTC
Repro using Version: 7.6.4.1 (X86_64) / LibreOffice Community
Build ID: e19e193f88cd6c0525a17fb7a176ed8e6a3e2aa1
CPU threads: 24; OS: Windows 10.0 Build 22631; UI render: Skia/Vulkan; VCL: win
Locale: ru-RU (en_US); UI: en-US
Calc: CL threaded

https://crashreport.libreoffice.org/stats/crash_details/20ba31b1-1f7e-4dba-b52a-853381899563
Comment 4 Henrry John 2023-12-26 09:45:52 UTC
(In reply to Mike Kaganski from comment #3)
> Repro using Version: 7.6.4.1 (X86_64) / LibreOffice Community
> Build ID: e19e193f88cd6c0525a17fb7a176ed8e6a3e2aa1
> CPU threads: 24; OS: Windows 10.0 Build 22631; UI render: Skia/Vulkan; VCL:
> win
> Locale: ru-RU (en_US); UI: en-US
> Calc: CL threaded
> 
> https://crashreport.libreoffice.org/stats/crash_details/20ba31b1-1f7e-4dba-
> b52a-853381899563

About the above link, am I supposed to do something with that? Apologies in advance since this is the first time I am ever reporting a bug, so I'm a bit confused.
Comment 5 Mike Kaganski 2023-12-26 11:10:33 UTC
(In reply to Henrry John from comment #4)
> About the above link, am I supposed to do something with that?

No, it is an additional data from my reproducing crash, intended to help whoever decides to fix it. Thanks for filing the bug. If some additional information would be required from you, a reply will ask it explicitly, don't worry.
Comment 6 Julien Nabet 2023-12-26 15:32:00 UTC
Created attachment 191598 [details]
gdb bt

On pc Debian x86-64 with master sources updated today, I could reproduce this.
Comment 7 Julien Nabet 2023-12-26 16:04:17 UTC
The pb is m_pDocShell->GetDoc() returns null whereas macro just created ""com.sun.star.text.TextDocument" object. Synchro pb? No idea how to fix this.
Comment 8 Mike Kaganski 2023-12-26 16:51:45 UTC
(In reply to Julien Nabet from comment #7)
> The pb is m_pDocShell->GetDoc() returns null whereas macro just created
> ""com.sun.star.text.TextDocument" object. Synchro pb?

No, it is correct: there is no document in the "com.sun.star.text.TextDocument" UNO object created like this (see Writer_SwTextDocument_get_implementation). The code in sw/source/uibase/uno/unotxdoc.cxx wrongly expects m_pDocShell->GetDoc() to return a non-null value. In line 2085, there should be a check for this (and I bet, that there will be lots of similar things over the file).
Comment 9 Mike Kaganski 2023-12-26 17:27:47 UTC
FTR: an example how this works is in SfxFrameLoader_Impl::load [1], which employs the Frame-Controller-Model Paradigm [2] [3]. In line 707, it creates an instance of the class (e.g., "com.sun.star.text.TextDocument"); then it either calls its attachResource (ln 713), or load (ln 720), to actually create/load the document.

Before calling these, the object is not properly initialized. Possibly the most correct is to have a check in the beginning of the UNO methods implementations, that would check if the doc is, and throw NotInitializedException [4] if it is not.

[1] https://opengrok.libreoffice.org/xref/core/sfx2/source/view/frmload.cxx?r=789a737a#706
[2] https://wiki.documentfoundation.org/Documentation/DevGuide/Office_Development#Frame-Controller-Model_Paradigm_in_LibreOffice
[3] https://wiki.documentfoundation.org/Documentation/DevGuide/Office_Development#Getting_Frames%2C_Controllers_and_Models_from_Each_Other
[4] https://api.libreoffice.org/docs/idl/ref/exceptioncom_1_1sun_1_1star_1_1lang_1_1NotInitializedException.html
Comment 10 Mike Kaganski 2023-12-27 06:47:15 UTC
https://gerrit.libreoffice.org/c/core/+/161366
Comment 11 Commit Notification 2023-12-27 09:31:50 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/4df22b4d3d4ae1ec0c4d32f614bd2cd8ec13143e

tdf#158862: check if document is initialized

It will be available in 24.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 12 Commit Notification 2024-01-02 11:16:43 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "libreoffice-24-2":

https://git.libreoffice.org/core/commit/b7faeeb19254a9cb696050016be052d776b2ef99

tdf#158862: check if document is initialized

It will be available in 24.2.0.2.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 13 Henrry John 2024-01-05 07:02:13 UTC
(In reply to Commit Notification from comment #12)
> Mike Kaganski committed a patch related to this issue.
> It has been pushed to "libreoffice-24-2":
> 
> https://git.libreoffice.org/core/commit/
> b7faeeb19254a9cb696050016be052d776b2ef99
> 
> tdf#158862: check if document is initialized
> 
> It will be available in 24.2.0.2.
> 
> The patch should be included in the daily builds available at
> https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
> information about daily builds can be found at:
> https://wiki.documentfoundation.org/Testing_Daily_Builds
> 
> Affected users are encouraged to test the fix and report feedback.

Thank you for the quick fix of the bug. As an average user, what should I do next? Should I wait for the next LibreOffice update to see the patch implemented, or is there something else I need to do? Apologies if this is a redundant question; I'm not familiar with software development cycles so there is a bit of confusion in my part.
Comment 14 Mike Kaganski 2024-01-05 07:26:27 UTC
(In reply to Henrry John from comment #13)

You may wait for the releases - see https://wiki.documentfoundation.org/ReleasePlan for schedule.

If you want to test, you may download dailies - as suggested in the commit notifications. Note that pre-release builds indeed are not intended for business-critical use, so only suitable for testing purposes.