Bug 128610 - "Import MathML from Clipboard", is broken on linux ( steps in comment 19 )
Summary: "Import MathML from Clipboard", is broken on linux ( steps in comment 19 )
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Formula Editor (show other bugs)
Version:
(earliest affected)
5.1 all versions
Hardware: All Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:7.4.0 target:7.3.3 target:7.2.7
Keywords:
Depends on:
Blocks: Clipboard MathML
  Show dependency treegraph
 
Reported: 2019-11-05 14:27 UTC by Juang Dse
Modified: 2022-03-15 11:01 UTC (History)
7 users (show)

See Also:
Crash report or crash signature:


Attachments
MathML file to test the bug (403 bytes, application/mathml+xml)
2019-11-05 14:27 UTC, Juang Dse
Details
clipboard content that parses into formula editor (25.05 KB, image/png)
2019-11-05 17:36 UTC, V Stuart Foote
Details
InsideClipboard captures (1.32 KB, application/zip)
2022-03-10 15:50 UTC, Xisco Faulí
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Juang Dse 2019-11-05 14:27:42 UTC
Created attachment 155533 [details]
MathML file to test the bug

Bug 117091 resurfaced. That is,

Open formula editor.
Copy some MathML into clipboard, e.g. the source of the attached file.
Use menu Tools, item "Import MathML from Clipboard".

Notice: nothing happens
Expected: A formula is generated.

Specifically:

Importing the file works, copying it to clipboard and importing doesn't:
Version: 6.2.8.2
Build ID: f82ddfca21ebc1e222a662a32b25c0c9d20169ee
CPU threads: 4; OS: Linux 4.19; UI render: default; VCL: gtk3; 
Locale: de-DE (en_US.utf8); UI-Language: en-US
Calc: threaded


Neither importing from file nor from clipboard works:
Version: 6.4.0.0.alpha1
Build ID: cc57df8f942f239d29cb575ea5a7cb01405db787
CPU threads: 4; OS: Linux 4.19; UI render: default; VCL: gtk3; 
Locale: de-DE (en_US.utf8); UI-Language: en-US
Calc: threaded
Comment 1 V Stuart Foote 2019-11-05 17:36:07 UTC
Created attachment 155541 [details]
clipboard content that parses into formula editor

Import from clipboard works on Windows builds

Version: 6.3.2.2 (x64)
Build ID: 98b30e735bda24bc04ab42594c85f7fd8be07b9c
CPU threads: 8; OS: Windows 10.0; UI render: GL; VCL: win; 
Locale: en-US (en_US); UI-Language: en-US
Calc: threaded

and a recent 6.4.0alpha1+ master
Version: 6.4.0.0.alpha1+ (x64)
Build ID: 3e8fb860d92160e41a1aef5a0a53e4447120eb2e
CPU threads: 8; OS: Windows 10.0 Build 18362; UI render: GL; VCL: win; 
Locale: en-US (en_US); UI-Language: en-US
Calc: threaded

copied text of attachment 155333 [details] to a new text document, deleted the annotation stanza (don't want that), saved document. Reopened in text editor--copied the MathML XML.

With LibreOffice sm Formula editor open, Tools -> 'Import MathML from Clipboard' renders the formula into the edit bar, and produces a correct formula nodes in the view pane.

InsideClipboard shows the XML as simple text clipboard formats as in attached.

And that unrecognized MathML text is parsed correctly on Windows builds.

Begs the question of what is present in clipboard on Linux build(s), if the same CF_ text types (no XML) then should parse into sm Formula editor the same as on Windows.
Comment 2 Juang Dse 2019-11-06 09:30:59 UTC
@V Stuart Foote: I am not sure whether your attached file is the correct one.

In Linux, I am pretty sure that the contents of my clipboard are what I see. I checked e.g. also with copyQ. Moreover, before invoking 'Import from clipboard' I simply pasted the clipboard into the formula editor, and from there cut it into the clipboard again – to no avail.
Comment 3 Regina Henschel 2019-11-06 12:53:11 UTC
I think, the problem is in version 6.2.8.

Juang Dse: Can you please try with the newest version of LibreOffice of the 6.3 family or with a LibreOffice daily build?
Comment 4 Juang Dse 2019-11-06 13:14:38 UTC
I don't think so. As mentioned above, neither importing from file nor from clipboard works for the current dev build (6.3 or 6.4).
Comment 5 V Stuart Foote 2019-11-06 13:34:58 UTC
Confirming the 'Import MathML from Clipboard' control is not functioning on Linux (Fedora 31). The attached .mml will open into LibreOffice Math formula editor. But content edited and clipped below does not import. Verified it is clipped and available to paste--pasting the XML into the edit pane, which of course gives nonsensical formmula nodes.

Version: 6.3.2.2
Build ID: 6.3.2.2-1.fc31
CPU threads: 2; OS: Linux 5.3; UI render: default; VCL: gtk3; 
Locale: en-US (en_US.UTF-8); UI-Language: en-US
Calc: threaded

<clip>

<?xml version="1.0" encoding="UTF-8"?>
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
 <semantics>
  <mrow>
   <msub>
    <mi>f</mi>
    <mi>c</mi>
   </msub>
   <mo stretchy="false">=</mo>
   <mfrac>
    <mn>1</mn>
    <msub>
     <mi>K</mi>
     <mi>m</mi>
    </msub>
   </mfrac>
  </mrow>
 </semantics>
</math>

</clip>
Comment 6 Caolán McNamara 2019-11-06 15:05:14 UTC
If I disable the UTF-16 hackery in there then it imports so its apparently related to that
Comment 7 Regina Henschel 2019-11-07 18:30:24 UTC
(In reply to Caolán McNamara from comment #6)
> If I disable the UTF-16 hackery in there then it imports so its apparently
> related to that

I know that my code is not good, but it had worked before the Math module has been switched to fast parser.

The "UTF-16 hackery" was needed for Windows "Math Input Panel", which puts the MathML only with encoding="utf-16" into the clipboard.
Comment 8 Caolán McNamara 2019-11-08 09:01:33 UTC
I presume windows is still working ? So there must be somewhere that is rejecting utf-16 under linux
Comment 9 Regina Henschel 2019-11-08 12:03:27 UTC
(In reply to Caolán McNamara from comment #8)
> I presume windows is still working ?

Import from Windows Math Input Panel still works, using Windows 10 and LO daily.
Comment 10 AJ Justin 2019-12-21 14:57:55 UTC Comment hidden (spam)
Comment 11 Julien Nabet 2020-06-13 17:09:08 UTC
On pc Debian x86-64 with master sources updated today, I could reproduce this.

I noticed this log on console:
warn:legacy.osl:80149:80149:starmath/source/mathmlimport.cxx:117: different SfxMedium found
Comment 12 Julien Nabet 2020-06-13 17:33:13 UTC
It works if I put:
<?xml version="1.0" encoding="UTF-8"?>
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
 <semantics>
  <mrow>
   <msub>
    <mi>f</mi>
    <mi>c</mi>
   </msub>
   <mo stretchy="false">=</mo>
   <mfrac>
    <mn>1</mn>
    <msub>
     <mi>K</mi>
     <mi>m</mi>
    </msub>
   </mfrac>
  </mrow>
 </semantics>
</math>

I got this formula:
{f_c = 1 over K_m}
+ this on console:
warn:starmath:80560:80560:starmath/source/mathmlimport.cxx:771: unknown attribute stretchy=false

but it doesn't work if I use the same block with xml declaration.
Comment 13 Xisco Faulí 2022-03-10 11:58:55 UTC
This issue is reproduced on linux

Version: 7.4.0.0.alpha0+ / LibreOffice Community
Build ID: 53560aa06462f1cf04d69acafed20da971bc5c27
CPU threads: 8; OS: Linux 5.10; UI render: default; VCL: gtk3
Locale: es-ES (es_ES.UTF-8); UI: en-US
Calc: threaded


but not on windows

Version: 7.4.0.0.alpha0+ (x64) / LibreOffice Community
Build ID: b1fe159fa39b2fc5217848e14d68c674979c181c
CPU threads: 16; OS: Windows 6.3 Build 9600; UI render: default; VCL: win
Locale: en-GB (en_GB); UI: en-US
Calc: threaded

which was fixed by Regina in bug 117091
Comment 14 Xisco Faulí 2022-03-10 12:00:45 UTC
(In reply to Caolán McNamara from comment #8)
> I presume windows is still working ? So there must be somewhere that is
> rejecting utf-16 under linux

yes, windows is still working
Comment 15 Xisco Faulí 2022-03-10 12:03:06 UTC
(In reply to Julien Nabet from comment #12)
> It works if I put:
> <?xml version="1.0" encoding="UTF-8"?>
> <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
>  <semantics>
>   <mrow>
>    <msub>
>     <mi>f</mi>
>     <mi>c</mi>
>    </msub>
>    <mo stretchy="false">=</mo>
>    <mfrac>
>     <mn>1</mn>
>     <msub>
>      <mi>K</mi>
>      <mi>m</mi>
>     </msub>
>    </mfrac>
>   </mrow>
>  </semantics>
> </math>
> 
> I got this formula:
> {f_c = 1 over K_m}
> + this on console:
> warn:starmath:80560:80560:starmath/source/mathmlimport.cxx:771: unknown
> attribute stretchy=false
> 
> but it doesn't work if I use the same block with xml declaration.

Not working for me. you are using "Import MathML from Clipboard", right ?
Comment 16 Xisco Faulí 2022-03-10 12:06:23 UTC
indeed, it works on Linux if UTF-16 is disabled.
@Mike, I thought you might be interested in this issue
Comment 17 Mike Kaganski 2022-03-10 12:49:13 UTC
Could you please provide *exact* steps to reproduce?

Specifically: how should the XML be put to clipboard. Should I open attachment 155533 [details] in a plain text editor, select it there and copy? Which one is known to produce the bug on which platform?
Or should I import it into Math, select and copy there?

(In reply to Regina Henschel from comment #9)
> (In reply to Caolán McNamara from comment #8)
> > I presume windows is still working ?
> 
> Import from Windows Math Input Panel still works, using Windows 10 and LO
> daily.

For the record. Math Input Panel on Windows puts data to clipboard in MathML clipboard format, which results in import code using the 'aDataHelper.HasFormat(SotClipboardFormatId::MATHML)' path, so it doesn't hit the UTF-16 replacement code.

Trying to open the MathML from the attachment into clipboard on Windows, using Notepad++ for that, and then trying to paste into Math using Tools->Import MathML from Clipboard does not insert anything, exactly because of the replacement of UTF-8 into UTF-16.

So I need to know what exactly this replacement should enable, to not break that scenario.

Thank you!
Comment 18 Xisco Faulí 2022-03-10 13:09:17 UTC
Doesn't work in 

Version: 5.2.0.0.alpha0+
Build ID: 3ca42d8d51174010d5e8a32b96e9b4c0b3730a53
Threads 4; Ver: 5.10; Render: default; 

Locale: en-US (en_US.UTF-8)

either
Comment 19 Xisco Faulí 2022-03-10 13:13:45 UTC
Steps to reproduce:
1. Copy

<?xml version="1.0" encoding="UTF-8"?>
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
 <semantics>
  <mrow>
   <msub>
    <mi>f</mi>
    <mi>c</mi>
   </msub>
   <mo stretchy="false">=</mo>
   <mfrac>
    <mn>1</mn>
    <msub>
     <mi>K</mi>
     <mi>m</mi>
    </msub>
   </mfrac>
  </mrow>
 </semantics>
</math>

2. Open Math
3. Go to Tools - Import MathML from Clipboard

-> Nothing happens.

This issue is only happening on Linux. On windows, it was fixed by Regina in bug 117091.
On linux, the issue is fixed if 

-                                    bForceUTF16 = true;
+                                    bForceUTF16 = false;

is changed in starmath/source/view.cxx:1847
Comment 20 Xisco Faulí 2022-03-10 13:15:51 UTC
Acording to https://wiki.documentfoundation.org/ReleaseNotes/5.1#Import_MathML_from_Clipboard, this feature was introduced in LibreOffice 5.1 by Regina, I'm wondering if it even worked on Linux
Comment 21 Mike Kaganski 2022-03-10 14:14:03 UTC
(In reply to Xisco Faulí from comment #19)
> This issue is only happening on Linux. On windows, it was fixed by Regina in
> bug 117091.

Wrong. I do the steps on Windows, copying the text you supplied, from Chrome (and from Notepad++ in earlier tests) into clipboard; and Tools - Import MathML from Clipboard does *not* put anything to Math, *unless* I change the code to avoid the UTF-16 replacement.

That is why I'm asking also which steps are needed to reproduce the scenario where that replacement is *needed*.

Note that you never mentioned *from which program* you copy the data to clipboard, as if it doesn't matter, despite I asked that explicitly ;)
Comment 22 Xisco Faulí 2022-03-10 14:31:07 UTC
(In reply to Mike Kaganski from comment #21)
> (In reply to Xisco Faulí from comment #19)
> > This issue is only happening on Linux. On windows, it was fixed by Regina in
> > bug 117091.
> 
> Wrong. I do the steps on Windows, copying the text you supplied, from Chrome
> (and from Notepad++ in earlier tests) into clipboard; and Tools - Import
> MathML from Clipboard does *not* put anything to Math, *unless* I change the
> code to avoid the UTF-16 replacement.
> 
> That is why I'm asking also which steps are needed to reproduce the scenario
> where that replacement is *needed*.
> 
> Note that you never mentioned *from which program* you copy the data to
> clipboard, as if it doesn't matter, despite I asked that explicitly ;)

mmm, this is interesting... In order to test windows issue, I connect to a win machine using Remmina. If I copy the code from Firefox on the windows machine it doesn't work. However, If I copy the code from Firefox on my linux machine and then I use "Import MathML from Clipboard" on the windows machine, then it works.
Comment 23 Mike Kaganski 2022-03-10 14:33:01 UTC
(In reply to Xisco Faulí from comment #22)

Great!
Could you please create a InsideClipboard capture on Windows machine, when the clipboard is defined using that procedure please?
Comment 24 Xisco Faulí 2022-03-10 14:53:42 UTC
(In reply to Xisco Faulí from comment #22)
> (In reply to Mike Kaganski from comment #21)
> > (In reply to Xisco Faulí from comment #19)
> > > This issue is only happening on Linux. On windows, it was fixed by Regina in
> > > bug 117091.
> > 
> > Wrong. I do the steps on Windows, copying the text you supplied, from Chrome
> > (and from Notepad++ in earlier tests) into clipboard; and Tools - Import
> > MathML from Clipboard does *not* put anything to Math, *unless* I change the
> > code to avoid the UTF-16 replacement.
> > 
> > That is why I'm asking also which steps are needed to reproduce the scenario
> > where that replacement is *needed*.
> > 
> > Note that you never mentioned *from which program* you copy the data to
> > clipboard, as if it doesn't matter, despite I asked that explicitly ;)
> 
> mmm, this is interesting... In order to test windows issue, I connect to a
> win machine using Remmina. If I copy the code from Firefox on the windows
> machine it doesn't work. However, If I copy the code from Firefox on my
> linux machine and then I use "Import MathML from Clipboard" on the windows
> machine, then it works.

it also works if you copy from Firefox to notepad and then from notepad to LibreOffice
Comment 25 Mike Kaganski 2022-03-10 15:05:20 UTC
(In reply to Xisco Faulí from comment #24)
> it also works if you copy from Firefox to notepad and then from notepad to
> LibreOffice

Doesn't work here. Please attach an InsideClipboard capture if possible. That would exclude any ambiguity.
Comment 26 Xisco Faulí 2022-03-10 15:50:43 UTC
Created attachment 178785 [details]
InsideClipboard captures

the bad file is when coping from Firefox. The good one when copying from notepad
Comment 27 Regina Henschel 2022-03-10 17:12:49 UTC
(In reply to Xisco Faulí from comment #26)
> Created attachment 178785 [details]
> InsideClipboard captures
> 
> the bad file is when coping from Firefox. The good one when copying from
> notepad

Are you sure about the files? They are identical.
Comment 28 Commit Notification 2022-03-11 14:04:48 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/c964700d16d99d1569373a1eb9a1352fb3512915

Related: tdf#128610 Avoid use-after-free

It will be available in 7.4.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 29 Mike Kaganski 2022-03-12 06:04:24 UTC
This ^ has fixed this issue. And the following one removes the replacement obsoleted by use of libxml2 instead of expat.
Comment 30 Commit Notification 2022-03-12 06:05:44 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/344353495c60dcdc69f7975ec4e51a753ebfb81f

Related: tdf#128610 drop obsolete encoding attribute replacement

It will be available in 7.4.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 31 Julien Nabet 2022-03-12 08:55:10 UTC
On pc Debian x86-64 with master sources updated today, I don't reproduce this anymore.

Thank you Mike for the fix!
Comment 32 Commit Notification 2022-03-14 13:24:24 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "libreoffice-7-3":

https://git.libreoffice.org/core/commit/aa705140c1891599202f918018ef54a6260174ce

Related: tdf#128610 Avoid use-after-free

It will be available in 7.3.3.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 33 Commit Notification 2022-03-14 14:26:10 UTC
Xisco Fauli committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/360e7eaef92ed38f25a454c8f0f605e7cda974f7

tdf#128610: math: add UItest

It will be available in 7.4.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 34 Commit Notification 2022-03-15 10:28:57 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "libreoffice-7-2":

https://git.libreoffice.org/core/commit/6fb5a87e31b7df01f4b212ab979ae57e8d4ab4fb

Related: tdf#128610 Avoid use-after-free

It will be available in 7.2.7.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 35 Xisco Faulí 2022-03-15 11:01:42 UTC
Verified in

Version: 7.2.7.0.0+ / LibreOffice Community
Build ID: 6fb5a87e31b7df01f4b212ab979ae57e8d4ab4fb
CPU threads: 8; OS: Linux 5.10; UI render: default; VCL: gtk3
Locale: es-ES (es_ES.UTF-8); UI: en-US
Calc: threaded

@Mike, thanks for fixing this issue!!