Bug 119039 - Writer crash when I try to open 4-pages DOCX
Summary: Writer crash when I try to open 4-pages DOCX
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
5.3 all versions
Hardware: All Windows (All)
: high major
Assignee: Mike Kaganski
URL:
Whiteboard: target:7.5.0 target:7.4.2
Keywords: bibisected, haveBacktrace, regression
Depends on:
Blocks: DOCX-OLE-Objects Crash
  Show dependency treegraph
 
Reported: 2018-08-01 13:28 UTC by Leonardo
Modified: 2022-09-21 11:01 UTC (History)
7 users (show)

See Also:
Crash report or crash signature: ["OleComponentNative_Impl::~OleComponentNative_Impl()"]


Attachments
document (1.58 MB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2018-08-01 13:35 UTC, Leonardo
Details
bt (70.49 KB, text/plain)
2019-01-29 14:02 UTC, Julien Nabet
Details
bt (27.98 KB, text/plain)
2022-09-09 19:43 UTC, Julien Nabet
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Leonardo 2018-08-01 13:28:10 UTC
Description:
when I try to open the document, writer hangs and nothing appears on the document recovery screen

Steps to Reproduce:
1. Open the document
2. Writer crash
3. 

Actual Results:
Writer crash

Expected Results:
the document should be shown


Reproducible: Always


User Profile Reset: No



Additional Info:
Comment 1 Leonardo 2018-08-01 13:35:28 UTC
Created attachment 143893 [details]
document
Comment 2 Xisco Faulí 2018-08-01 13:45:16 UTC
Not reproducible in

Versió: 6.0.6.1
ID de la construcció: 1:6.0.6~rc1-0ubuntu0.16.04.1
Fils de CPU: 4; SO: Linux 4.15; Renderitzador de la IU: per defecte; VCL: gtk3; 
Configuració local: ca-ES (ca_ES.UTF-8); Calc: group

thus, only WIN
Comment 3 Xisco Faulí 2018-08-01 13:47:15 UTC
Not reproducible in

Versión: 4.4.0.3
Id. de compilación: de093506bcdc5fafd9023ee680b8c60e3e0645d7
Configuración regional: es_ES
Comment 5 Xisco Faulí 2018-08-01 14:14:36 UTC
I'm wondering if it was introduced by aa0d0536a444fb26d9e570bd6bf6c1bdc3596cf3...
Comment 6 Julien Nabet 2019-01-29 14:02:35 UTC
Created attachment 148735 [details]
bt

On Win7 with master sources updated today, I could reproduce this.

I noticed this on console:
warn:oox:4556:1016:oox/source/docprop/docprophandler.cxx:325: OOXMLDocPropHandler::startFastElement: unknown element 5619
warn:oox:4556:1016:oox/source/docprop/docprophandler.cxx:325: OOXMLDocPropHandler::startFastElement: unknown element 3198
warn:vcl.gdi:4556:1016:vcl/source/graphic/Manager.cxx:136: Calculated size mismatch. Variable size is '1013512' but calculated size is '573060'
warn:legacy.osl:4556:1016:svx/source/unodraw/unoshape.cxx:1976: SvxShape::GetAnyForItem() Returnvalue has wrong Type!
warn:writerfilter:4556:1016:writerfilter/source/dmapper/OLEHandler.cxx:257: OLEHandler::getCLSID: unhandled m_sProgId: StaticMetafile
warn:legacy.osl:4556:1016:writerfilter/source/dmapper/StyleSheetTable.cxx:1558: Exception in StyleSheetTable::getOrCreateCharStyle - Style::setPropertyValue
warn:vcl.gdi:4556:1016:vcl/source/graphic/Manager.cxx:136: Calculated size mismatch. Variable size is '1491912' but calculated size is '1040168'
warn:legacy.osl:4556:1016:svx/source/unodraw/unoshape.cxx:1976: SvxShape::GetAnyForItem() Returnvalue has wrong Type!
Comment 7 housesofglory 2019-12-25 14:51:38 UTC Comment hidden (no-value)
Comment 8 QA Administrators 2022-05-17 03:30:55 UTC Comment hidden (obsolete)
Comment 9 Timur 2022-09-05 08:32:38 UTC
Repro 7.5+. I set Major for crash and High for regression.
Comment 10 Noel Grandin 2022-09-09 07:15:59 UTC
This is crashing down in the OLEComponent desctructor and it looks like the reference counting on a Windows COM object has gone weird somehow.
Comment 11 Julien Nabet 2022-09-09 19:43:11 UTC
Created attachment 182346 [details]
bt

On Windows 10 with master sources updated today, I could still reproduce this.

This time instead of using:
!analyze -v
I tried:
kp
this one gives:
file name + associated line
parameters provided to the function.

If it can help, here's what I got on Cygwin console:
warn:legacy.osl:4740:19232:sal/osl/w32/file_url.cxx:849: osl_getAbsoluteFileURL called with empty base URL and/or invalid relative URL
warn:extensions.olebridge:4740:19232:extensions/source/ole/olethread.cxx:39: CoInitializeEx failed (expectedly): Impossible de modifier le mode thread une fois qu’il a été fixé.
warn:extensions.olebridge:4740:19232:extensions/source/ole/olethread.cxx:59:   Thread is in a main single-threaded apartment.
warn:vcl:4740:19232:vcl/source/image/ImplImage.cxx:82: Failed to load scaled image from cmd/sc_signaturesmenu.png at 1
warn:vcl:4740:19232:vcl/source/image/ImplImage.cxx:105: Failed to load stock icon cmd/sc_signaturesmenu.png
warn:vcl:4740:19232:vcl/source/window/menu.cxx:2917: Available height misdetected as 652px. Setting to 768px instead.
warn:sfx.dialog:4740:19232:sfx2/source/dialog/filtergrouping.cxx:359: already have an element for WordPerfect
warn:sfx.dialog:4740:19232:sfx2/source/dialog/filtergrouping.cxx:359: already have an element for writerweb8_writer_template
warn:sfx.dialog:4740:19232:sfx2/source/dialog/filtergrouping.cxx:359: already have an element for writerglobal8
warn:xmloff:4740:19232:sax/source/fastparser/fastparser.cxx:1324: unknown element xsi:type http://www.w3.org/2001/XMLSchema-instance
warn:xmloff:4740:19232:sax/source/fastparser/fastparser.cxx:1324: unknown element xsi:type http://www.w3.org/2001/XMLSchema-instance
warn:xmloff:4740:19232:sax/source/fastparser/fastparser.cxx:1248: unknown attribute vid={4A3C46E8-61CC-4603-A589-7422A47A8E4A}
warn:legacy.osl:4740:19232:svx/source/unodraw/unoshape.cxx:1870: SvxShape::GetAnyForItem() Returnvalue has wrong Type!
warn:svx:4740:19232:svx/source/unodraw/unoshap2.cxx:1461: Getting Graphic by URL is not supported, getting it by value
warn:drawinglayer.emf:4740:19232:drawinglayer/source/tools/emfphelperdata.cxx:1791: EMF+         TODO SetPixelOffsetMode
warn:drawinglayer.emf:4740:19232:drawinglayer/source/tools/emfphelperdata.cxx:1778: EMF+         TODO SetAntiAliasMode
warn:drawinglayer.emf:4740:19232:drawinglayer/source/tools/emfphelperdata.cxx:1785: EMF+         TODO InterpolationMode
warn:writerfilter:4740:19232:writerfilter/source/dmapper/OLEHandler.cxx:260: OLEHandler::getCLSID: unhandled m_sProgId: StaticMetafile
warn:writerfilter:4740:19232:writerfilter/source/dmapper/DomainMapper_Impl.cxx:7616: PopFieldContext() com.sun.star.lang.IllegalArgumentException ArgumentPosition: 0
warn:writerfilter:4740:19232:writerfilter/source/dmapper/DomainMapper_Impl.cxx:7616: PopFieldContext() com.sun.star.lang.IllegalArgumentException ArgumentPosition: 0
warn:legacy.osl:4740:19232:svx/source/unodraw/unoshape.cxx:1870: SvxShape::GetAnyForItem() Returnvalue has wrong Type!
warn:svx:4740:19232:svx/source/unodraw/unoshap2.cxx:1461: Getting Graphic by URL is not supported, getting it by value
warn:drawinglayer.emf:4740:19232:drawinglayer/source/tools/emfphelperdata.cxx:1791: EMF+         TODO SetPixelOffsetMode
warn:drawinglayer.emf:4740:19232:drawinglayer/source/tools/emfphelperdata.cxx:1778: EMF+         TODO SetAntiAliasMode
warn:drawinglayer.emf:4740:19232:drawinglayer/source/tools/emfphelperdata.cxx:1785: EMF+         TODO InterpolationMode
Comment 12 Julien Nabet 2022-09-09 21:43:37 UTC
Just for the record because I'm suppose it's wrong, if I delete this:
delete m_pNativeImpl;
(see https://opengrok.libreoffice.org/xref/core/embeddedobj/source/msole/olecomponent.cxx?r=7b8f630d#373)
File can be opened on Windows.

It seems there's something wrong with m_pNativeImpl->m_pIStorage

m_pNativeImpl is ok but if I try something like:
m_pNativeImpl->m_pIStorage = nullptr;
it segfaults.
Comment 13 Julien Nabet 2022-09-10 07:14:29 UTC
Mike: thought you might be interested in this one since you've already worked on Windows specific part.
Comment 14 Noel Grandin 2022-09-10 14:05:29 UTC
The pointer

   m_pNativeImpl->m_pIStorage

is a smart pointer to a COM object, which is supposed to be managing the COM AddRef/Release calls for us.

But we must be missing a COM AddRef call somewhere, because the COM object seems to be dying sooner than it should, which is why when we that last Release() call to it, we end up trying to access data on an already deleted area of memory.
Comment 15 Mike Kaganski 2022-09-10 14:17:51 UTC
(In reply to Noel Grandin from comment #14)

Thanks Noel!
Indeed, that is the object causing the double release in its dtor; but the problem here seems to not be a missing AddRef, but rather some internal error.

The object is assigned and used (and double-released) inside OleComponent::LoadEmbeddedObject. It is assigned using a path to a temporary file, which definitely exists at the moment; and the call to StgOpenStorage definitely creates an already AddRef'ed object, and is normal with all COM API that takes a void** to assign.

Then in OleLoadSeh, a call to OleLoad MS API is done, and it's here where the underlying COM object is released - because of an error trying to load it. I do not know why they allow that happen at all - an error is not an excuse to manage something they didn't AddRef'd; but IMO, we need to try to find out if we can prevent the STG_E_FILENOTFOUND from OleLoadSeh. And if that fails, we could *workaround* it using an AddRef before the call, and conditional Release when it's not STG_E_FILENOTFOUND.
Comment 16 Mike Kaganski 2022-09-10 14:44:09 UTC
OK, this is a Windows bug:

https://developercommunity.visualstudio.com/t/OleLoad-can-release-passed-LPSTORAGE-on/10144795

I'll create a workaround as mentioned above.
Comment 17 Mike Kaganski 2022-09-10 20:05:16 UTC
https://gerrit.libreoffice.org/c/core/+/139756
Comment 18 Commit Notification 2022-09-10 21:39:24 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

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

tdf#119039: workaround an OleLoad bug releasing passed storage unexpectedly

It will be available in 7.5.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 19 Roman Kuznetsov 2022-09-11 14:15:00 UTC
Confirm , no crash in

Version: 7.5.0.0.alpha0+ (x64) / LibreOffice Community
Build ID: bff60eadeac348024849d710690435ee9580831b
CPU threads: 4; OS: Windows 10.0 Build 19043; UI render: Skia/Raster; VCL: win
Locale: ru-RU (ru_RU); UI: en-US
Calc: threaded

Mike, thanks for fixing!
Comment 20 Julien Nabet 2022-09-11 18:40:11 UTC
I confirm I don't reproduce the bug too, thank you Mike!
Comment 21 Commit Notification 2022-09-21 11:01:39 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "libreoffice-7-4":

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

tdf#119039: workaround an OleLoad bug releasing passed storage unexpectedly

It will be available in 7.4.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.