From 12362fc496102b344dedef0a6ba130ba80b94149 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Fri, 21 May 2021 13:38:32 +0200 Subject: LineParser::readNextToken gets called with m_nCharIndex==npos after all eca89ece45ede76605a6102c94b3b67e1f8ff5aa "Replace rtl_string_getTokenView with o3tl::getToken" had erroneously assumed (from a succeeding `make check`) that the only problematic call to o3tl::getToken with position==npos would be the one in LineParser::readPath (and which had been addressed in that commit). But e.g. loading ooo29794-4.pdf from the crash test corpus would also run into that situation via LineParser::readNextToken, > warn:legacy.osl:3090875:3090875:sdext/source/pdfimport/wrapper/wrapper.cxx:259: insufficient input > soffice.bin: include/o3tl/string_view.hxx:34: std::string_view o3tl::getToken(std::string_view, char, std::size_t &): Assertion `position <= sv.size()' failed. > #3 0x00007ffff7a67a16 in __GI___assert_fail (assertion=0x7fffb39ea58c "position <= sv.size()", file=0x7fffb39f2a7f "include/o3tl/string_view.hxx", line=34, function=0x7fffb39ef3a9 "std::string_view o3tl::getToken(std::string_view, char, std::size_t &)") > #4 0x00007fffb3b60131 in o3tl::getToken(std::basic_string_view >, char, unsigned long&) (sv="eoClipPath", delimiter=32 ' ', position=@0x7fffffff29e0: 18446744073709551615) at include/o3tl/string_view.hxx:34 > #5 0x00007fffb3b5aa9f in pdfi::(anonymous namespace)::LineParser::readNextToken() (this=0x7fffffff29d0) at sdext/source/pdfimport/wrapper/wrapper.cxx:260 > #6 0x00007fffb3b5b2fa in pdfi::(anonymous namespace)::LineParser::readPath() (this=0x7fffffff29d0) at sdext/source/pdfimport/wrapper/wrapper.cxx:323 > #7 0x00007fffb3b59eb3 in pdfi::(anonymous namespace)::Parser::parseLine(rtl::OString const&) (this=0x7fffffff2d28, rLine="eoClipPath") at sdext/source/pdfimport/wrapper/wrapper.cxx:859 [...] so better guard there. Change-Id: Ibfd53fd9d3be0a3548d60cb26d59bb5966c5bc2c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115916 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- sdext/source/pdfimport/wrapper/wrapper.cxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'sdext') diff --git a/sdext/source/pdfimport/wrapper/wrapper.cxx b/sdext/source/pdfimport/wrapper/wrapper.cxx index 78fb9cd0b331..2221f1ebe33f 100644 --- a/sdext/source/pdfimport/wrapper/wrapper.cxx +++ b/sdext/source/pdfimport/wrapper/wrapper.cxx @@ -256,7 +256,10 @@ OString lcl_unescapeLineFeeds(std::string_view i_rStr) std::string_view LineParser::readNextToken() { - OSL_PRECOND(m_nCharIndex!=std::string_view::npos,"insufficient input"); + if (m_nCharIndex == std::string_view::npos) { + SAL_WARN("sdext.pdfimport", "insufficient input"); + return {}; + } return o3tl::getToken(m_aLine,' ',m_nCharIndex); } -- cgit