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
Created attachment 181503 [details] Error message claiming the file is corrupt, which is not This is screenshot of the error message.
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.
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
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.
Actually maybe not, as there is aNewStream->SetEndian(SvStreamEndian::LITTLE); I'll investigate when the build finishes
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.
(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
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
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.