summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2022-11-17 13:15:27 +0000
committerCaolán McNamara <caolanm@redhat.com>2022-11-17 17:12:48 +0100
commitf44f5f12605f32d92c2c1689e3e6888337eca2d9 (patch)
treeb682ee47945d19522a0cda1d3a43d3e4443f9bf9
parentd6a3510ebc04dd5f24366f5b6426060cb149c3ff (diff)
ofz#53457 sanity check the form field range
Change-Id: I2a1c82bb0590acf8f2399f2ea4b6b477600c7908 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142840 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sw/qa/core/data/ww8/pass/ofz53457-1.docbin0 -> 17454 bytes
-rw-r--r--sw/source/filter/ww8/ww8par5.cxx19
2 files changed, 17 insertions, 2 deletions
diff --git a/sw/qa/core/data/ww8/pass/ofz53457-1.doc b/sw/qa/core/data/ww8/pass/ofz53457-1.doc
new file mode 100644
index 000000000000..b847eedbbdef
--- /dev/null
+++ b/sw/qa/core/data/ww8/pass/ofz53457-1.doc
Binary files differ
diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx
index 513ee98e0edb..7e7cedd3f4b5 100644
--- a/sw/source/filter/ww8/ww8par5.cxx
+++ b/sw/source/filter/ww8/ww8par5.cxx
@@ -503,6 +503,20 @@ void SwWW8ImplReader::UpdateFields()
m_rDoc.SetInitDBFields(true); // Also update fields in the database
}
+// Sanity check the PaM to see if it makes sense wrt sw::CalcBreaks
+static bool SanityCheck(const SwPaM& rFieldPam)
+{
+ SwNodeOffset const nEndNode(rFieldPam.End()->GetNodeIndex());
+ SwNodes const& rNodes(rFieldPam.GetPoint()->GetNodes());
+ SwNode *const pFinalNode(rNodes[nEndNode]);
+ if (pFinalNode->IsTextNode())
+ {
+ SwTextNode & rTextNode(*pFinalNode->GetTextNode());
+ return (rTextNode.Len() >= rFieldPam.End()->GetContentIndex());
+ }
+ return true;
+}
+
sal_uInt16 SwWW8ImplReader::End_Field()
{
sal_uInt16 nRet = 0;
@@ -530,10 +544,11 @@ sal_uInt16 SwWW8ImplReader::End_Field()
if (bUseEnhFields && m_pPaM!=nullptr && m_pPaM->GetPoint()!=nullptr) {
SwPosition aEndPos = *m_pPaM->GetPoint();
SwPaM aFieldPam( m_aFieldStack.back().GetPtNode().GetNode(), m_aFieldStack.back().GetPtContent(), aEndPos.GetNode(), aEndPos.GetContentIndex());
+
IDocumentMarkAccess* pMarksAccess = m_rDoc.getIDocumentMarkAccess( );
- IFieldmark *pFieldmark = pMarksAccess->makeFieldBookmark(
+ IFieldmark *pFieldmark = SanityCheck(aFieldPam) ? pMarksAccess->makeFieldBookmark(
aFieldPam, m_aFieldStack.back().GetBookmarkName(), ODF_FORMTEXT,
- aFieldPam.Start() /*same pos as start!*/ );
+ aFieldPam.Start() /*same pos as start!*/ ) : nullptr;
OSL_ENSURE(pFieldmark!=nullptr, "hmmm; why was the bookmark not created?");
if (pFieldmark!=nullptr) {
// adapt redline positions to inserted field mark start