sw, createTextRangeByPixelPosition(): fix crash when the position is an image

Desktop / LibreOffice - Miklos Vajna [collabora.com] - 22 November 2022 09:07 UTC

Using createTextRangeByPixelPosition() with a pixel position that leads to a graphic node resulted in a crash.

The direct reason for this is that the makeMark() call in SwXTextRange::SetPositions() returns nullptr in case rPaM points to a graphic node, but later we dereference that result unconditionally. This also uncovers that the XTextRange returned by createTextRangeByPixelPosition() is meant to point to a text node, but a pixel position may be closest to a graphic node.

Fix the problem by explicitly checking for graphic nodes; and try to look up the anchor position of such graphics, which will be definitely a text node.

In practice this will mean that in case the image's anchor type is as-char, then we'll return a cursor position which will be on the left hand side of the image.

Change-Id: Ief58148247fe3cd4371ed245b4eff5b45ca2aa15 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143092

2302ebefb2e2 sw, createTextRangeByPixelPosition(): fix crash when the position is an image
.../sun/star/text/XTextViewTextRangeSupplier.idl | 7 ++-
sw/qa/uibase/uno/uno.cxx | 57 ++++++++++++++++++++++
sw/source/uibase/uno/unotxvw.cxx | 18 +++++++
3 files changed, 81 insertions(+), 1 deletion(-)

Upstream: cgit.freedesktop.org


  • Share