Bug 167948 - LibreOffice crashes when calling insertDocumentFromURL with a HTML file
Summary: LibreOffice crashes when calling insertDocumentFromURL with a HTML file
Status: RESOLVED DUPLICATE of bug 167936
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: sdk (show other bugs)
Version:
(earliest affected)
25.2.0.3 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-08-14 06:40 UTC by Adomas Venčkauskas
Modified: 2025-08-14 10:35 UTC (History)
0 users

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adomas Venčkauskas 2025-08-14 06:40:27 UTC
Description:
Zotero users of LibreOffice 25.2 have started reporting LibreOffice crashes when attempting to insert notes into their documents. I have investigated our code and determined it to be the call to insertDocumentFromURL which is causing it.

The issue is not present in major releases previous to 25.2.

Steps to Reproduce:
Run `insertText("<html><body>Comment: 38 pages, 13 figures, 6 tables. Submitted to Phys. Rev. D</body></html>")`:

```
	public void insertText(String textString) throws Exception {
		XTextCursor viewCursor = getSelection();
		
		XText text = viewCursor.getText();
		XTextCursor cursor = text.createTextCursorByRange(viewCursor);
		XTextRange preNewline, postNewline;
		
		preNewline = text.createTextCursorByRange(viewCursor).getStart();
		postNewline = text.createTextCursorByRange(viewCursor).getEnd();
		
		// move citation to its own paragraph so its formatting isn't altered automatically
		// because of the text on either side of it
		text.insertControlCharacter(preNewline, ControlCharacter.PARAGRAPH_BREAK, true);
		text.insertControlCharacter(postNewline, ControlCharacter.PARAGRAPH_BREAK, true);

		insertHTML(textString, cursor);

		// remove previously added paragraphs
		preNewline.setString("");
		postNewline.setString("");
	}

	public void insertHTML(String text, XTextCursor cursor) throws Exception {
		PropertyValue filterName = new PropertyValue();
		filterName.Name = "FilterName";
		filterName.Value = "HTML Document";
		PropertyValue inputStream = new PropertyValue();
		inputStream.Name = "InputStream";
		try {
			inputStream.Value = new StringInputStream(text.getBytes("ISO-8859-1"));
		} catch (UnsupportedEncodingException e) {
			return;
		}
		
		((XDocumentInsertable) UnoRuntime.queryInterface(XDocumentInsertable.class, cursor)).
			insertDocumentFromURL("private:stream", new PropertyValue[] {filterName, inputStream});
	}
```

Actual Results:
LibreOffice 25.2+ crashes

Expected Results:
LibreOffice inserts the HTML and continues running.


Reproducible: Always


User Profile Reset: No

Additional Info:
Version: 25.2.5.2 (X86_64) / LibreOffice Community
Build ID: 03d19516eb2e1dd5d4ccd751a0d6f35f35e08022
CPU threads: 16; OS: Linux 6.8; UI render: default; VCL: gtk3
Locale: lt-LT (en_US.UTF-8); UI: en-US
Calc: threaded
Comment 1 Mike Kaganski 2025-08-14 07:28:30 UTC
(In reply to Adomas Venčkauskas from comment #0)
> Steps to Reproduce:
> Run `insertText("<html><body>Comment: 38 pages, 13 figures, 6 tables.
> Submitted to Phys. Rev. D</body></html>")`:
> 
> ```
> 	public void insertText(String textString) throws Exception {
> 		XTextCursor viewCursor = getSelection();
> ...

Is "getSelection" a global function in some (unstated) language? How can one "run" this?
Comment 2 Adomas Venčkauskas 2025-08-14 07:48:22 UTC
Sorry, I was copying this from our codebase and trimming parts that are not relevant.

```
	public XTextViewCursor getSelection() {
		XTextViewCursorSupplier supplier = (XTextViewCursorSupplier) UnoRuntime.queryInterface(XTextViewCursorSupplier.class, controller);
		return supplier.getViewCursor();
	}
```
Comment 3 Mike Kaganski 2025-08-14 07:58:20 UTC
(In reply to Adomas Venčkauskas from comment #2)

... and `controller` is...?
Please, provide something that can be used to just run. E.g., the same code implemented in Basic. Or a standalone application (this is Java? A .java file would do, that us runnable simply by `java --class-path path/to/libreoffice.jar path/to/yourprogram.jar`)
Comment 4 Mike Kaganski 2025-08-14 07:59:06 UTC
(In reply to Mike Kaganski from comment #3)
> path/to/libreoffice.jar path/to/yourprogram.jar`)

heh, `yourprogram.java` was meant, of course
Comment 5 Mike Kaganski 2025-08-14 08:23:29 UTC
StringInputStream is also undefined
Comment 6 Adomas Venčkauskas 2025-08-14 08:47:24 UTC
Sorry. It seems some things were missing and we have a custom StringInputStream implementation. Here's a fork of the starter extension with the reproduction case https://github.com/adomasven/libreoffice-java-starter-extension/tree/lo25.2-insert-html-crash
Comment 7 Mike Kaganski 2025-08-14 09:37:40 UTC
FTR: the following Basic code works fine in Version: 25.8.0.3 (X86_64)
Build ID: ab0112984cb0c13cf3d4edd063593d096a42a1aa
CPU threads: 24; OS: Windows 11 X86_64 (build 26100); UI render: Skia/Vulkan; VCL: win
Locale: de-DE (en_US); UI: en-US
Calc: CL threaded

sub insertHTML()
  const html = "<html><body>Comment: 38 pages, 13 figures, 6 tables. Submitted to Phys. Rev. D</body></html>"
  dim html_bytes (1 to Len(html))
  for i = 1 to len(html)
    html_bytes(i) = Asc(Mid(html, i, 1))
  next i

  viewCursor = ThisComponent.CurrentController.getViewCursor()

  text = viewCursor.getText()
  cursor = text.createTextCursorByRange(viewCursor)

  preNewline = text.createTextCursorByRange(viewCursor).getStart()
  postNewline = text.createTextCursorByRange(viewCursor).getEnd()

  text.insertControlCharacter(preNewline, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, true)
  text.insertControlCharacter(postNewline, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, true)

  filterName = new com.sun.star.beans.PropertyValue
  filterName.Name = "FilterName"
  filterName.Value = "HTML Document"
  inputStream = new com.sun.star.beans.PropertyValue
  inputStream.Name = "InputStream"
  inputStream.Value = com.sun.star.io.SequenceInputStream.createStreamFromSequence(html_bytes)

  cursor.insertDocumentFromURL("private:stream", array(filterName, inputStream))

  preNewline.setString("")
  postNewline.setString("")
end sub

I didn't try the extension - it still requires to build it, it seems. There is still no easy way to reproduce.
Comment 8 Adomas Venčkauskas 2025-08-14 10:02:41 UTC
Ok, thanks for the pointer to SequenceInputStream. I've updated our code with it, and it works, without the crash. I don't know why we've been using a custom InputStream implementation, since I've inherited this code written in 2009 without notes, aside from a link to this thread.

I've pushed the built extension, in case you think it might be important to address this, since it is technically a regression and might pop up somewhere else? https://github.com/adomasven/libreoffice-java-starter-extension/raw/refs/heads/lo25.2-insert-html-crash/dist/StarterProject.oxt

The extension with the custom InputStream implementation works fine in LibreOffice 24 and all prior versions.
Comment 9 Mike Kaganski 2025-08-14 10:26:36 UTC
Thanks for the compiled extension - yes it's a regression.

*** This bug has been marked as a duplicate of bug 167936 ***