summaryrefslogtreecommitdiff
path: root/sax
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2019-11-16 16:34:25 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2019-11-16 20:13:40 +0100
commit9fdf8c0a5cc036ea9bd1e11dd8f2c1a6e601fae2 (patch)
tree0723081e68e21987a4f6b5ad89ce63eb075458ce /sax
parentcbfc87cb39406045e6f561a178bec3c7d10fae02 (diff)
Also consider saved exceptions when terminating parse
As with previous commit 18ae77a065cb8ae6940d4067f6ab7e99a3f74047, this will start showing parse errors on invalid files which previously just opened without warnings, silently losing the invalid stream part. Any bug bisected to this commit is not a regression from this commit! The real problem was already before, and was just disclosed by this (which is the actual goal). Also simplify unit test data for tdf#128820, which will now be enough after the change. A unit test (testN779627) revealed unexpected throws when parsing; this was fixed. Change-Id: I5a21b9001874ec6e3b8273c10043ef930bf1cc82 Reviewed-on: https://gerrit.libreoffice.org/82981 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sax')
-rw-r--r--sax/source/fastparser/fastparser.cxx14
1 files changed, 11 insertions, 3 deletions
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index 7383b8c339ea..9b35c1682be5 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -175,6 +175,8 @@ struct Entity : public ParserData
css::uno::Any maSavedException;
osl::Mutex maSavedExceptionMutex;
void saveException( const Any & e );
+ // Thread-safe check if maSavedException has value
+ bool hasException();
void throwException( const ::rtl::Reference< FastLocatorImpl > &xDocumentLocator,
bool mbDuringParse );
@@ -622,6 +624,12 @@ void Entity::saveException( const Any & e )
}
}
+bool Entity::hasException()
+{
+ osl::MutexGuard g(maSavedExceptionMutex);
+ return maSavedException.hasValue();
+}
+
} // namespace
namespace sax_fastparser {
@@ -1040,6 +1048,8 @@ void FastSaxParserImpl::parse()
{
if( xmlParseChunk( rEntity.mpParser, reinterpret_cast<const char*>(seqOut.getConstArray()), 0, 1 ) != XML_ERR_OK )
rEntity.throwException( mxDocumentLocator, true );
+ if (rEntity.hasException())
+ rEntity.throwException(mxDocumentLocator, true);
}
break;
}
@@ -1068,10 +1078,8 @@ void FastSaxParserImpl::parse()
{
rEntity.throwException( mxDocumentLocator, true );
}
- osl::ClearableMutexGuard g(rEntity.maSavedExceptionMutex);
- if (rEntity.maSavedException.hasValue())
+ if (rEntity.hasException())
{
- g.clear();
rEntity.throwException( mxDocumentLocator, true );
}
} while( nRead > 0 );