Bug 150201 - Opening wmf file containing placeable header fails
Summary: Opening wmf file containing placeable header fails
Status: CLOSED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
7.5.0.0 alpha0+
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:7.5.0
Keywords: bibisected, regression
Depends on:
Blocks: EMF-WMF
  Show dependency treegraph
 
Reported: 2022-07-30 15:53 UTC by Hossein
Modified: 2024-04-11 23:07 UTC (History)
3 users (show)

See Also:
Crash report or crash signature:


Attachments
Error message claiming the file is corrupt, which is not (71.29 KB, image/png)
2022-07-30 15:59 UTC, Hossein
Details
WMF file with placeable header: tdf88163-wrong-font-size.wmf (1.26 KB, image/wmf)
2022-07-31 10:01 UTC, Hossein
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Hossein 2022-07-30 15:53:56 UTC
Description:
WMF files can be opened directly or inserted as images. Recently, opening some wmf files fails. As an example, try opening this file:

emfio/qa/cppunit/wmf/data/tdf88163-wrong-font-size.wmf

Steps to Reproduce:
1. Open emfio/qa/cppunit/wmf/data/tdf88163-wrong-font-size.wmf in LibreOffice


Actual Results:
Error message, claiming that the file is corrupt, which is not.

Expected Results:
File should be opened and displayed like the previous versions


Reproducible: Always


User Profile Reset: No



Additional Info:
Version: 7.5.0.0.alpha0+ / LibreOffice Community
Build ID: 640a6488a32e8f682788feb6cab01acfffca7fa7
CPU threads: 8; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded
Comment 1 Hossein 2022-07-30 15:59:58 UTC
Created attachment 181503 [details]
Error message claiming the file is corrupt, which is not

This is screenshot of the error message.
Comment 2 Hossein 2022-07-30 16:02:17 UTC
Regression bibisected to:

commit 56bfb93d0028b735adaddd7d23be96145a7bd2ed
Author: offtkp <parisoplop@gmail.com>
Date:   Tue May 24 16:28:08 2022 +0300

    Detect WMF from header instead of extension
    
    Change ImpDetectWMF function to detect a WMF file
    from its header instead of just comparing the extension.
Comment 3 Hossein 2022-07-30 16:26:16 UTC
It seems that placeable wmf files can not be opened. These files have the META_PLACEABLE record, as described here:

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-wmf/9a40a350-7fe8-42be-a8fe-c2e28dac6970

https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-wmf/828e1864-7fe7-42d8-ab0a-1de161b32f27

Non-placeable wmf files are still opened without problem. As an example, try opening this file:

emfio/qa/cppunit/wmf/data/tdf88163-non-placeable.wmf

It should be opened without problem.

To see the structure of the WMF files with placeable header record, see this:

https://en.wikipedia.org/wiki/Windows_Metafile#WMF
Comment 4 Paris Oplopoios 2022-07-30 16:44:22 UTC
vcl/source/filter/graphicfilter2.cxx:37

constexpr sal_uInt32 PLACEABLE_SIGNATURE = 0xd7cdc69a;

Wrong endianness. Correct value should be 0x9ac6cdd7

I'll upload a patch to fix this after LO build finishes so I can confirm the file opens correctly.
Comment 5 Paris Oplopoios 2022-07-30 16:46:14 UTC
Actually maybe not, as there is aNewStream->SetEndian(SvStreamEndian::LITTLE);

I'll investigate when the build finishes
Comment 6 Roman Kuznetsov 2022-07-30 18:43:22 UTC
repro in

Version: 7.5.0.0.alpha0+ / LibreOffice Community
Build ID: 8580cbdc19224bc2a467535cc527cd28b0f30879
CPU threads: 4; OS: Mac OS X 12.5; UI render: Skia/Metal; VCL: osx
Locale: ru-RU (ru_RU.UTF-8); UI: en-US
Calc: threaded Jumbo

I tried just open the WMF file. And I got next message:

The file '150201 wrong-font-size.wmf' is corrupt and therefore cannot be opened. LibreOfficeDev can try to repair the file.
The corruption could be the result of document manipulation or of structural document damage due to data transmission.
We recommend that you do not trust the content of the repaired document.
Execution of macros is disabled for this document.
Should LibreOfficeDev repair the file? Yes/No

But if you try add the WMF to Writer document using Insert image icon on the toolbar then LO just inserts the WMF to the document.
Comment 7 Paris Oplopoios 2022-07-30 18:58:51 UTC
(In reply to Roman Kuznetsov from comment #6)
> repro in
> 
> Version: 7.5.0.0.alpha0+ / LibreOffice Community
> Build ID: 8580cbdc19224bc2a467535cc527cd28b0f30879
> CPU threads: 4; OS: Mac OS X 12.5; UI render: Skia/Metal; VCL: osx
> Locale: ru-RU (ru_RU.UTF-8); UI: en-US
> Calc: threaded Jumbo
> 
> I tried just open the WMF file. And I got next message:
> 
> The file '150201 wrong-font-size.wmf' is corrupt and therefore cannot be
> opened. LibreOfficeDev can try to repair the file.
> The corruption could be the result of document manipulation or of structural
> document damage due to data transmission.
> We recommend that you do not trust the content of the repaired document.
> Execution of macros is disabled for this document.
> Should LibreOfficeDev repair the file? Yes/No
> 
> But if you try add the WMF to Writer document using Insert image icon on the
> toolbar then LO just inserts the WMF to the document.

Yes, probably because WMF detection in Writer uses GraphicFormatDescriptor and in Draw it uses GraphicDescriptor, which has wrong endianness when detecting the placeable key.

With patch https://gerrit.libreoffice.org/c/core/+/137634 I can open tdf88163-wrong-font-size.wmf correctly
Comment 8 Hossein 2022-07-31 10:01:16 UTC
Created attachment 181507 [details]
WMF file with placeable header: tdf88163-wrong-font-size.wmf

The is the example file from core repository:

emfio/qa/cppunit/wmf/data/tdf88163-wrong-font-size.wmf
Comment 9 Commit Notification 2022-07-31 13:42:55 UTC
offtkp committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/826fea9d77dbb7f4ea71f934bbe137008aa8b7f0

tdf#150201 Fix endianness for placeable WMF

It will be available in 7.5.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.