ebandal / H2Orestart

한컴파일을 LibreOffice에서 읽을 수 있도록 하는 extension입니다.
GNU General Public License v3.0
75 stars 6 forks source link

Conversion fails on ARM systems #12

Closed apyrgio closed 10 months ago

apyrgio commented 10 months ago

First of all, thanks a lot @ebandal for this project! We are currently using it in Dangerzone, to sanitize HWP / HWPX files.

While the extension seems to work great on x86 machines, it doesn't seem to work on ARM machines. The platform where we detected this issue is MacOS with Apple Silicon CPU, but note that we are using Docker in this case, so the actual OS is Alpine Linux.

We have opened an issue (https://github.com/freedomofpress/dangerzone/issues/498) in our issue tracker, where @OctopusET has been kindly helping us figure out what's going on. I'm opening an issue here as well though, since this problem does not seem to be Dangerzone-related, and probably affects all users in ARM devices.

Copying here from the original issue the instructions to reproduce this error:

If one tries to convert the file to PDF via Libreoffice:

libreoffice --headless --infilter="Hwp2002_Reader" --convert-to pdf:writer_pdf_Export <file>

they will get the following generic error:

Error: source file could not be loaded
ebandal commented 10 months ago

I don't have mac device. but I will try to reproduce this issue in any ARM system. I wrote filter name of extension incorrectly somewhere once, that has mislead the usage. infilter="Hwp2002_File" is the correct one. In first trial on Ubuntu on ARM machine, conversion from hwp to pdf done.

ubuntu@instance-20230816-2224:~$ uname -a
Linux instance-20230816-2224 5.15.0-1038-oracle #44-Ubuntu SMP Thu Jun 22 03:34:10 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux
ubuntu@instance-20230816-2224:~$ libreoffice --headless --infilter="Hwp2002_File" --convert-to pdf:writer_pdf_Export HWP97.hwp
[08-18 19:53] (riterContext.dete) INFO: file detected not HWPX
[08-18 19:53] (riterContext.dete) INFO: file detected neither HWPX nor HWP
[08-18 19:53] (OrestartImpl.dete) INFO: File is not Hancomm document.
convert /home/ubuntu/HWP97.hwp -> /home/ubuntu/HWP97.pdf using filter : writer_pdf_Export
Overwriting: /home/ubuntu/HWP97.pdf

I will keep posted what I try on other ARM system.

OctopusET commented 10 months ago

I will try again with correct filter name on my ARM device(Raspberry Pi 4) too.

Thank you for all your work @ebandal

ebandal commented 10 months ago

I tried on postmarketos on ARM, and reproduced it.

xiaomi-tissot:~$ uname -a
Linux xiaomi-tissot 6.3.0-postmarketos-qcom-msm8953 #3-postmarketos-qcom-msm8953 SMP PREEMPT Sat May 27 04:34:36 UTC aarch64 Linux
xiaomi-tissot:~$ libreoffice --headless --infilter="Hwp2002_File" --convert-to pdf:writer_pdf_Export Finish.hwp
Error: source file could not be loaded

"source file could not be loaded" message seems to be shown in libreoffice. no expected log from H2O restart. so I check installation status of extension. but extension is not installed correctly. is registered: no is shown.

xiaomi-tissot:~$ sudo unopkg list --shared
All deployed shared extensions:

Identifier: ebandal.libreoffice.H2Orestart
  Version: 0.5.5
  URL: vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE/uno_packages/lu31804fyklq3.tmp_/H2Orestart.oxt
  is registered: no
  Media-Type: application/vnd.sun.star.package-bundle
  Description: LibreOffice HWP 5.0 import Extension.
This product was developed by referring to the ᄒᆞᆫ글 document file (HWP, HWPML) published by 한글과컴퓨터.
Please report bugs to https://github.com/ebandal/H2Orestart
  bundled Packages: {
      URL: vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE/uno_packages/lu31804fyklq3.tmp_/H2Orestart.oxt/H2Orestart.jar
      is registered: no
      Media-Type: application/vnd.sun.star.uno-component;type=Java
      Description:

      URL: vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE/uno_packages/lu31804fyklq3.tmp_/H2Orestart.oxt/registry/H2Orestart_types.xcu
      is registered: no
      Media-Type: application/vnd.sun.star.configuration-data
      Description:

      URL: vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE/uno_packages/lu31804fyklq3.tmp_/H2Orestart.oxt/registry/H2Orestart_filters.xcu
      is registered: no
      Media-Type: application/vnd.sun.star.configuration-data
      Description:

      URL: vnd.sun.star.expand:$UNO_SHARED_PACKAGES_CACHE/uno_packages/lu31804fyklq3.tmp_/H2Orestart.oxt/registry/TypeDetection.xcu
      is registered: no
      Media-Type: application/vnd.sun.star.configuration-data
      Description:

  }

I tried to remove extension and re-install. but unopkg not working.

xiaomi-tissot:~$ sudo unopkg remove --shared ebandal.libreoffice.H2Orestart
ERROR: Exception occurred: An error occurred while enabling: H2Orestart.jar: com.sun.star.registry.CannotRegisterImplementationException "ImplementationRegistration::registerImplementation() - The service com.sun.star.loader.Java2 cannot be instantiated at /home/buildozer/aports/community/libreoffice/src/libreoffice-7.5.4.2/stoc/source/implementationregistration/implreg.cxx:1275" at /home/buildozer/aports/community/libreoffice/src/libreoffice-7.5.4.2/desktop/source/deployment/registry/dp_backend.cxx:662 at /home/buildozer/aports/community/libreoffice/src/libreoffice-7.5.4.2/desktop/source/deployment/registry/package/dp_package.cxx:851

ERROR: unopkg failed.

I will research this symptom and keep posted.

OctopusET commented 10 months ago

Would you try with GUI? It's weird but if you open libreoffice GUI, then CLI conversion works.

It doesn't matter if you open libreoffice or libreoffice writer, both of them work.

Edit: If you can't use GUI at all, you can try running soffice on other place (terminal, tmux, tty... e.g.). Then try running converting script again.

OctopusET commented 10 months ago

And it was able to get more error information with "--safe-mode" option.

ebandal commented 10 months ago

Would you try with GUI? It's weird but if you open libreoffice GUI, then CLI conversion works.

It doesn't matter if you open libreoffice or libreoffice writer, both of them work.

Edit: If you can't use GUI at all, you can try running soffice on other place (terminal, tmux, tty... e.g.). Then try running converting script again.

I can't use GUI with postmarketos device. CLI result is same. My assumption is that the results vary depending on whether or not the H2Orestart installed correctly. If H2Orestart installed correctly, then you can see the log like "INFO: file detected not HWPX".

ebandal commented 10 months ago

I filed an issue report on Alpine Linux and got the answer. Alpine aarch64 package of libreoffice has been built without Java support whereas x86_64 is built with Java support.

https://gitlab.alpinelinux.org/alpine/aports/-/issues/15212

OctopusET commented 10 months ago

Alpine team enabled the Java support on the aarch64 system. https://gitlab.alpinelinux.org/alpine/aports/-/commit/74d443f479df15fc57e6fde6ac02a36b24afdded

It's only on the edge, stable(3.18) repository doesn't have that package yet.

So I ran the following script to install libreoffice from the edge repository on alpine 3.18. But it seems not to work.

$ apk add libreoffice --repository=https://dl-cdn.alpinelinux.org/alpine/edge/community

Ref: https://stackoverflow.com/questions/52899227/alpine-add-package-from-edge-repository

When I try on the edge version of Alpine, conversion works great. Thank you so much @ebandal!

apyrgio commented 10 months ago

Thank you both for digging into this :star_struck: . What you fixed here (the LibreOffice issue on Alpine) goes beyond the H2ORestart extension, which is super great. I consider this issue closed from the side of H2ORestart, and I'll resume the discussion on the Dangerzone side, so that we can fix it there as well.