[Libreoffice-commits] core.git: Branch 'libreoffice-6-0' - sax/source
Michael Stahl
mstahl at redhat.com
Mon Jan 8 09:15:37 UTC 2018
sax/source/fastparser/fastparser.cxx | 33 ++++++++++++++++++++++++++++++---
1 file changed, 30 insertions(+), 3 deletions(-)
New commits:
commit 25b0538b1af6fd2f9646ff875523a6ddd77c9ce4
Author: Michael Stahl <mstahl at redhat.com>
Date: Fri Jan 5 15:36:59 2018 +0100
ofz#4392 sax: guard access to Entity::maSavedException with mutex
The problem here is presumably that the parser thread reports a
low-level SAX exception and the main thread reports a high-level filter
exception at the same time, so both threads modify maSavedException
concurrently.
Change-Id: Ic8ce9a4992208a24a111c990a67be163858ddaf8
Reviewed-on: https://gerrit.libreoffice.org/47478
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
Tested-by: Jenkins <ci at libreoffice.org>
(cherry picked from commit 2a88f62ac01daa72b6287a8cedccfb78579a6067)
Reviewed-on: https://gerrit.libreoffice.org/47539
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index 1aa8811366ea..4d4ec416e7a4 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -173,6 +173,7 @@ struct Entity : public ParserData
// resource leaks), therefore any exception thrown by a UNO callback
// must be saved somewhere until the C-XmlParser is stopped.
css::uno::Any maSavedException;
+ osl::Mutex maSavedExceptionMutex;
void saveException( const Any & e );
void throwException( const ::rtl::Reference< FastLocatorImpl > &xDocumentLocator,
bool mbDuringParse );
@@ -584,12 +585,20 @@ void Entity::throwException( const ::rtl::Reference< FastLocatorImpl > &xDocumen
bool mbDuringParse )
{
// Error during parsing !
+ Any savedException;
+ {
+ osl::MutexGuard g(maSavedExceptionMutex);
+ if (maSavedException.hasValue())
+ {
+ savedException.setValue(&maSavedException, cppu::UnoType<decltype(maSavedException)>::get());
+ }
+ }
SAXParseException aExcept(
lclGetErrorMessage( mpParser,
xDocumentLocator->getSystemId(),
xDocumentLocator->getLineNumber() ),
Reference< XInterface >(),
- Any( &maSavedException, cppu::UnoType<decltype(maSavedException)>::get() ),
+ savedException,
xDocumentLocator->getPublicId(),
xDocumentLocator->getSystemId(),
xDocumentLocator->getLineNumber(),
@@ -621,7 +630,15 @@ void Entity::saveException( const Any & e )
// for XComponent; and yet expect to continue parsing.
SAL_WARN("sax", "Unexpected exception from XML parser "
<< e.get<Exception>());
- maSavedException = e;
+ osl::MutexGuard g(maSavedExceptionMutex);
+ if (maSavedException.hasValue())
+ {
+ SAL_INFO("sax.fastparser", "discarding exception, already have one");
+ }
+ else
+ {
+ maSavedException = e;
+ }
}
} // namespace
@@ -838,6 +855,8 @@ void FastSaxParserImpl::parseStream(const InputSource& maStructSource)
deleteUsedEvents();
// callbacks used inside XML_Parse may have caught an exception
+ // No need to lock maSavedExceptionMutex here because parser
+ // thread is joined.
if( rEntity.maSavedException.hasValue() )
rEntity.throwException( mxDocumentLocator, true );
}
@@ -1047,8 +1066,16 @@ void FastSaxParserImpl::parse()
}
// callbacks used inside XML_Parse may have caught an exception
- if( !bContinue || rEntity.maSavedException.hasValue() )
+ if (!bContinue)
+ {
rEntity.throwException( mxDocumentLocator, true );
+ }
+ osl::ClearableMutexGuard g(rEntity.maSavedExceptionMutex);
+ if (rEntity.maSavedException.hasValue())
+ {
+ g.clear();
+ rEntity.throwException( mxDocumentLocator, true );
+ }
} while( nRead > 0 );
rEntity.getEvent( DONE );
if( rEntity.mbEnableThreads )
More information about the Libreoffice-commits
mailing list