diff options
author | Miklos Vajna <vmiklos@suse.cz> | 2012-10-22 23:38:54 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@suse.cz> | 2012-10-23 09:42:52 +0200 |
commit | 49e003177db4c5e83bfe9feeb4d12d472f97f3cb (patch) | |
tree | b8dfa96255a54b46cae8a955decf94f8d7998569 /writerfilter | |
parent | de574fe542ccec288c3a5e240a6888d545e8d744 (diff) |
fdo#51145 give better error message on import invalid RTF
Change-Id: Idd81e58b8b0b95b1027b7ece434cb362a689f124
Diffstat (limited to 'writerfilter')
-rw-r--r-- | writerfilter/qa/cppunittests/rtftok/testrtftok.cxx | 10 | ||||
-rw-r--r-- | writerfilter/source/filter/RtfFilter.cxx | 5 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 6 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtftokenizer.cxx | 18 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtftokenizer.hxx | 3 |
5 files changed, 36 insertions, 6 deletions
diff --git a/writerfilter/qa/cppunittests/rtftok/testrtftok.cxx b/writerfilter/qa/cppunittests/rtftok/testrtftok.cxx index b416d78a490d..7cdec4979f9d 100644 --- a/writerfilter/qa/cppunittests/rtftok/testrtftok.cxx +++ b/writerfilter/qa/cppunittests/rtftok/testrtftok.cxx @@ -29,6 +29,7 @@ #include <unotest/filters-test.hxx> #include <test/bootstrapfixture.hxx> #include <com/sun/star/document/XFilter.hpp> +#include <com/sun/star/io/WrongFormatException.hpp> #include <osl/file.hxx> #include <osl/process.h> @@ -65,7 +66,14 @@ bool RtfTest::load(const OUString &, const OUString &rURL, const OUString &) uno::Sequence< beans::PropertyValue > aDescriptor(1); aDescriptor[0].Name = "URL"; aDescriptor[0].Value <<= rURL; - return m_xFilter->filter(aDescriptor); + try + { + return m_xFilter->filter(aDescriptor); + } + catch (const io::WrongFormatException&) + { + return false; + } } void RtfTest::test() diff --git a/writerfilter/source/filter/RtfFilter.cxx b/writerfilter/source/filter/RtfFilter.cxx index 35f84da26bd0..9b7a87900b95 100644 --- a/writerfilter/source/filter/RtfFilter.cxx +++ b/writerfilter/source/filter/RtfFilter.cxx @@ -27,6 +27,7 @@ #include <rtftok/RTFDocument.hxx> #include <com/sun/star/frame/XFrame.hpp> #include <com/sun/star/task/XStatusIndicator.hpp> +#include <com/sun/star/io/WrongFormatException.hpp> #ifdef DBG_COPYPASTE #include <unotools/localfilehelper.hxx> #include <tools/stream.hxx> @@ -116,6 +117,10 @@ sal_Bool RtfFilter::filter( const uno::Sequence< beans::PropertyValue >& aDescri sal_uInt32 nEndTime = osl_getGlobalTimer(); SAL_INFO("writerfilter.profile", OSL_THIS_FUNC << " finished in " << nEndTime - nStartTime << " ms"); } + catch (const io::WrongFormatException&) + { + throw; + } catch (const uno::Exception& e) { SAL_INFO("writerfilter", "Exception caught: " << e.Message); diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index 452c107f1fc1..9010b51dc258 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -578,15 +578,15 @@ void RTFDocumentImpl::resolve(Stream & rMapper) break; case ERROR_GROUP_OVER: SAL_INFO("writerfilter", OSL_THIS_FUNC << ": unmatched '{'"); - throw io::UnexpectedEOFException(); + throw io::WrongFormatException(m_pTokenizer->getPosition(), uno::Reference< uno::XInterface >()); break; case ERROR_EOF: SAL_INFO("writerfilter", OSL_THIS_FUNC << ": unexpected end of file"); - throw io::UnexpectedEOFException(); + throw io::WrongFormatException(m_pTokenizer->getPosition(), uno::Reference< uno::XInterface >()); break; case ERROR_HEX_INVALID: SAL_INFO("writerfilter", OSL_THIS_FUNC << ": invalid hex char"); - throw io::WrongFormatException(); + throw io::WrongFormatException(m_pTokenizer->getPosition(), uno::Reference< uno::XInterface >()); break; case ERROR_CHAR_OVER: SAL_INFO("writerfilter", OSL_THIS_FUNC << ": characters after last '}'"); diff --git a/writerfilter/source/rtftok/rtftokenizer.cxx b/writerfilter/source/rtftok/rtftokenizer.cxx index 3e7a7503d526..471462ce4344 100644 --- a/writerfilter/source/rtftok/rtftokenizer.cxx +++ b/writerfilter/source/rtftok/rtftokenizer.cxx @@ -47,7 +47,9 @@ RTFTokenizer::RTFTokenizer(RTFDocumentImpl& rImport, SvStream* pInStream, uno::R m_pInStream(pInStream), m_xStatusIndicator(xStatusIndicator), m_aRTFControlWords(std::vector<RTFSymbol>(aRTFControlWords, aRTFControlWords + nRTFControlWords)), - m_nGroup(0) + m_nGroup(0), + m_nLineNumber(0), + m_nLineStartPos(0) { std::sort(m_aRTFControlWords.begin(), m_aRTFControlWords.end()); } @@ -128,8 +130,11 @@ int RTFTokenizer::resolveParse() return ret; break; case 0x0d: + break; // ignore this case 0x0a: - break; // ignore these + m_nLineNumber++; + m_nLineStartPos = nCurrentPos; + break; default: if (m_nGroup == 0) return ERROR_CHAR_OVER; @@ -335,6 +340,15 @@ int RTFTokenizer::dispatchKeyword(OString& rKeyword, bool bParam, int nParam) return 0; } +OUString RTFTokenizer::getPosition() +{ + OUStringBuffer aRet; + aRet.append(m_nLineNumber + 1); + aRet.append(","); + aRet.append(sal_Int32(Strm().Tell() - m_nLineStartPos + 1)); + return aRet.makeStringAndClear(); +} + } // namespace rtftok } // namespace writerfilter diff --git a/writerfilter/source/rtftok/rtftokenizer.hxx b/writerfilter/source/rtftok/rtftokenizer.hxx index 2fd06ae82b09..94cbe402e857 100644 --- a/writerfilter/source/rtftok/rtftokenizer.hxx +++ b/writerfilter/source/rtftok/rtftokenizer.hxx @@ -49,6 +49,7 @@ namespace writerfilter { void pushGroup(); /// To be invoked by the popState() callback to single when the importer leaves a group. void popGroup(); + OUString getPosition(); private: SvStream& Strm(); int resolveKeyword(); @@ -61,6 +62,8 @@ namespace writerfilter { std::vector<RTFSymbol> m_aRTFControlWords; /// Same as the size of the importer's states, except that this can be negative for invalid input. int m_nGroup; + sal_Int32 m_nLineNumber; + sal_Int32 m_nLineStartPos; }; } // namespace rtftok } // namespace writerfilter |