Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HWP conversion fails on MacOS M1 #498

Closed
apyrgio opened this issue Aug 2, 2023 · 31 comments · Fixed by #541 or #649
Closed

HWP conversion fails on MacOS M1 #498

apyrgio opened this issue Aug 2, 2023 · 31 comments · Fixed by #541 or #649
Labels
Milestone

Comments

@apyrgio
Copy link
Contributor

apyrgio commented Aug 2, 2023

HWP conversion was recently added in #460 and was tested across various platforms (Windows, MacOS, Linux) through our CI. However, when running our tests on a MacOS M1 platform (which is not available through any of our CI runners), we get the following error:

[DEBUG] Marking doc UWYs15 as 'converting'
[INFO ] > /usr/local/bin/docker run --network none -u dangerzone --security-opt=no-new-privileges:true --cap-drop all --rm -v /var/folders/7c/49675rcx2nb0lwjms_6wmdpr0000gs/T/tmp6rzrqzt1/unsafe/input_file:/tmp/input_file:Z -v /var/folders
/7c/49675rcx2nb0lwjms_6wmdpr0000gs/T/tmp6rzrqzt1/pixels:/tmp/dangerzone:Z -e ENABLE_TIMEOUTS=1 dangerzone.rocks/dangerzone /usr/bin/python3 -m dangerzone.conversion.doc_to_pixels
[INFO ] [doc UWYs15] 0% UNTRUSTED> Installing LibreOffice extension 'h2orestart.oxt'
[INFO ] [doc UWYs15] 0% UNTRUSTED> Converting to PDF using LibreOffice                                 
[INFO ] [doc UWYs15] 3% UNTRUSTED> Calculating number of pages
[ERROR] [doc UWYs15] 3% UNTRUSTED> PDF file is corrupted

(taken from the dangerzone-cli)

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

Note that the exact same operation in an Intel MacOS device works.

@apyrgio apyrgio added bug Something isn't working container labels Aug 2, 2023
@apyrgio apyrgio added this to the 0.4.2 milestone Aug 2, 2023
@deeplow
Copy link
Contributor

deeplow commented Aug 2, 2023

Maybe we should add to this release a note in the changelog that this is not yet support on arm macs.

And this is yet another case where the error message is confusing because it looks like pdfinfo is the one failing (saying that the PDF was corrupted), where in reality it wasn't even produced since LibreOffice failed.

@deeplow deeplow added the P:mac label Aug 2, 2023
@OctopusET
Copy link
Contributor

I will take a look at this issue. I can borrow the m1 macbook for testing soon.

@apyrgio
Copy link
Contributor Author

apyrgio commented Aug 2, 2023

One assumption is that H2Orestart, the plugin we rely on for HWP conversions, somehow fails on ARM platforms. This is further reinforced by the fact that of the 3 HWP-related test files that we have under tests/test_docs_exernal:

sample-hwp.hwp.b64
sample-hwp97.hwp.b64
sample-hwpx.hwpx.b64

only two of those fail (sample-hwp.hwp.b64 and sample-hwpx.hwpx.b64). The sample-hwp97.hwp.b64 file passes, probably because LibreOffice already had support for it.

There's one issue with this assumption though: H2Orestart is a Java plugin, meaning that it should work across architectures, bar some exceptions. These exceptions usually boil down to usage of JNI (see this SO answer), but that's something we can detect. If we do jar tf h2orestart.jar, we get back a list of .class files, which should be platform agnostic.

@OctopusET thanks a lot for taking a look at it. Tagging @ebandal as well, in case they are interested in this issue as well.

@deeplow
Copy link
Contributor

deeplow commented Aug 3, 2023

Following some feedback, we have two options here:
a) not ship the hwp feature until it's fully working across the board (I guess we can ignore Qubes for now)
b) Inform users that choose hwp or hwpx file on arm Macs that it's not supported (via an alert, for example)
c) fix the bug, of course.

I'd rather go for option b) if c) is not possible. It should be relatively trivial to implement.

@OctopusET
Copy link
Contributor

I can use the M1 macbook after August 8 for dangerzone development. Before that I can only try some conversion in M1 macbook with h2orestart.

apyrgio added a commit that referenced this issue Aug 3, 2023
The HWP / HWPX conversion feature does not work on the following
platforms:

* MacOS with Apple Silicon CPU
* Native Qubes OS

For this reason, we need to:

1. Disable it on the GUI side, by not allowing the user to select these
   files.
2. Throw an error on the isolation provider side, in case the user
   directly attempts to convert the file (either through CLI or via
   "Open With").

Refs #494
Refs #498
apyrgio added a commit that referenced this issue Aug 3, 2023
The HWP / HWPX conversion feature does not work on the following
platforms:

* MacOS with Apple Silicon CPU
* Native Qubes OS

For this reason, we need to:

1. Disable it on the GUI side, by not allowing the user to select these
   files.
2. Throw an error on the isolation provider side, in case the user
   directly attempts to convert the file (either through CLI or via
   "Open With").

Refs #494
Refs #498
apyrgio added a commit that referenced this issue Aug 3, 2023
The HWP / HWPX conversion feature does not work on the following
platforms:

* MacOS with Apple Silicon CPU
* Native Qubes OS

For this reason, we need to:

1. Disable it on the GUI side, by not allowing the user to select these
   files.
2. Throw an error on the isolation provider side, in case the user
   directly attempts to convert the file (either through CLI or via
   "Open With").

Refs #494
Refs #498
apyrgio added a commit that referenced this issue Aug 3, 2023
The HWP / HWPX conversion feature does not work on the following
platforms:

* MacOS with Apple Silicon CPU
* Native Qubes OS

For this reason, we need to:

1. Disable it on the GUI side, by not allowing the user to select these
   files.
2. Throw an error on the isolation provider side, in case the user
   directly attempts to convert the file (either through CLI or via
   "Open With").

Refs #494
Refs #498
apyrgio added a commit that referenced this issue Aug 3, 2023
The HWP / HWPX conversion feature does not work on the following
platforms:

* MacOS with Apple Silicon CPU
* Native Qubes OS

For this reason, we need to:

1. Disable it on the GUI side, by not allowing the user to select these
   files.
2. Throw an error on the isolation provider side, in case the user
   directly attempts to convert the file (either through CLI or via
   "Open With").

Refs #494
Refs #498
apyrgio added a commit that referenced this issue Aug 3, 2023
The HWP / HWPX conversion feature does not work on the following
platforms:

* MacOS with Apple Silicon CPU
* Native Qubes OS

For this reason, we need to:

1. Disable it on the GUI side, by not allowing the user to select these
   files.
2. Throw an error on the isolation provider side, in case the user
   directly attempts to convert the file (either through CLI or via
   "Open With").

Refs #494
Refs #498
apyrgio added a commit that referenced this issue Aug 3, 2023
The HWP / HWPX conversion feature does not work on the following
platforms:

* MacOS with Apple Silicon CPU
* Native Qubes OS

For this reason, we need to:

1. Disable it on the GUI side, by not allowing the user to select these
   files.
2. Throw an error on the isolation provider side, in case the user
   directly attempts to convert the file (either through CLI or via
   "Open With").

Refs #494
Refs #498
deeplow pushed a commit that referenced this issue Aug 5, 2023
The HWP / HWPX conversion feature does not work on the following
platforms:

* MacOS with Apple Silicon CPU
* Native Qubes OS

For this reason, we need to:

1. Disable it on the GUI side, by not allowing the user to select these
   files.
2. Throw an error on the isolation provider side, in case the user
   directly attempts to convert the file (either through CLI or via
   "Open With").

Refs #494
Refs #498
@OctopusET
Copy link
Contributor

I just started work on M1 macbook yesterday.
Seems like just conversion with H2Orestart is working.

Question: I just drop the commit that is "HWP/HWPX disable on MacOS Apple Silicon", is there any way to re-enable the HWP/HWPX conversion feature on MacOS Appli Silicon?

@OctopusET
Copy link
Contributor

And with Dangerzone GUI, there's an issue with selecting the HWP/HWPX files. You can't select it. So, I tried with only CLI.

@deeplow
Copy link
Contributor

deeplow commented Aug 9, 2023

Question: I just drop the commit that is "HWP/HWPX disable on MacOS Apple Silicon", is there any way to re-enable the HWP/HWPX conversion feature on MacOS Appli Silicon?

Thanks for looking into this. We can do this but only for the next release since we just shipped this one. However, @apyrgio did experience this issue, so it may still happen particular files.

And with Dangerzone GUI, there's an issue with selecting the HWP/HWPX files. You can't select it. So, I tried with only CLI.

We decided to remove the ability to add these files in platforms where they were considered not compatible. Not a perfect solution, but it leads to avoiding getting errors later.

@deeplow deeplow modified the milestones: 0.4.2, 0.5.0 Aug 9, 2023
@OctopusET
Copy link
Contributor

@deeplow, Ah, I mean, is there any way to re-enable that feature other than dropping commits.

@deeplow
Copy link
Contributor

deeplow commented Aug 9, 2023

I think it's no big deal. We can always do another commit that does the reverse.

@OctopusET
Copy link
Contributor

With my short analyses, it fails when it's checking converted file is exist or not.
I think it's almost the same issue as the previous one. #460 (comment).
Libreoffice might work differently on MacOS.

I think it's not H2ORestart's issue. I tested with several files including the our test files.

@OctopusET
Copy link
Contributor

I can't use my borrowed M1 Macbook everyday. It might take while for actual testing.

@OctopusET
Copy link
Contributor

It's strange because the conversion worked for me, but the issue said it didn't even work.

So I restart my Macbook.
I found very strange behavior.

I tried the HWP->PDF, HWPX->PDF conversion on cold booted macbook.
It failed like you mentioned at first. But, after you open libreoffice GUI, it's working.

And if you kill libreoffice, like with killall soffice.
It fails again.

@OctopusET
Copy link
Contributor

If you try with --safe-mode option, there are some additional error logs.

$ soffice --safe-mode --headless --infilter="Hwp2002_Reader" --convert-to pdf:writer_pdf_Export some.hwp
libc++abi: terminating due to uncaught exception of type com::sun::star::deployment::DeploymentException
Unspecified Application Error

@apyrgio
Copy link
Contributor Author

apyrgio commented Aug 22, 2023

@ebandal did a nice dig and probed the Alpine Linux devs: https://gitlab.alpinelinux.org/alpine/aports/-/issues/15212. Turns out that the LibreOffice package for aarch64 does not support Java. Hopefully this will be resolved upstream. Once it does, we should remove our GUI restrictions for this platform.

@apyrgio apyrgio removed this from the 0.5.0 milestone Aug 22, 2023
@OctopusET
Copy link
Contributor

@OctopusET
Copy link
Contributor

I think rebuilding image would fix it. I will test it soon.

@OctopusET
Copy link
Contributor

I had to change the docker image to alpine:edge (20230901).
But it works!
capture

@apyrgio
Copy link
Contributor Author

apyrgio commented Sep 5, 2023

Nice, thanks for staying on top of this. I'll take a look at your PR and associated issue and we'll fix this.

apyrgio added a commit that referenced this issue Sep 6, 2023
The Alpine Linux team has enabled Java support for LibreOffice on ARM
architecture:

    https://gitlab.alpinelinux.org/alpine/aports/-/commit/74d443f479df15fc57e6fde6ac02a36b24afdded

This commit is included in 7.5.5.2-r2, so the installed LibreOffice
package should be 7.5.5.2-r2 or higher to fix this issue.

However 3.18 doesn't have the 7.5.5.2-r2 package:

    https://pkgs.alpinelinux.org/package/v3.18/community/aarch64/libreoffice

The Dangerzone image uses the alpine:latest image which is 3.18 as of
writing this.

For this reason, we switch to the edge repo of Alpine Linux, which
includes this fix.

Refs #498
Refs #540
Refs #542
apyrgio added a commit that referenced this issue Sep 6, 2023
This PR reverts the patch that disables HWP / HWPX conversion on MacOS
M1. It does not fix conversion on Qubes OS (#494)

Previously, HWP / HWPX conversion didn't work on MacOS M1 systems (#498)
because libreoffice wasn't built with Java support on Alpine Linux for
ARM (aarch64).

Gratefully, the Alpine team has enabled Java support on the aarch64
system [1], so we can enable it again for ARM architectures.

Fixes #498

[1]: https://gitlab.alpinelinux.org/alpine/aports/-/commit/74d443f479df15fc57e6fde6ac02a36b24afdded
@apyrgio apyrgio closed this as completed in 214ce97 Sep 6, 2023
@apyrgio
Copy link
Contributor Author

apyrgio commented Sep 28, 2023

@OctopusET: Quick update now that we are about to cut the 0.5.0 release. We wanted to switch back to alpine:latest (see #542) before the release, provided that the required LibreOffice version is in the repos. This does not seem to be the case, so we had two options at hand: either release on alpine:edge, or stay with alpine:latest and not include the latest fixes.

Ultimately, we decided that we don't want to risk any last minute breaking changes from the edge repo. This means that we will revert your fixes for now, and wait until November, for the new release of Alpine Linux, to properly include them.

It's a bit of a tough decision, but we believe it's best to prioritize the stability of the software over new features. Thank you for your persistence on this feature, and rest assured that the next release will include it 🙂.

@apyrgio apyrgio reopened this Sep 28, 2023
@OctopusET
Copy link
Contributor

I agree with you about stability concerns.
And eventually the package will be updated, so no need to rush for this.

Thank you for letting me know about this

@apyrgio apyrgio added this to the 0.5.1 milestone Oct 2, 2023
apyrgio added a commit that referenced this issue Oct 2, 2023
This reverts commit acd615e. The
rationale is that we want to wait until the LibreOffice package that
allows HWP conversion in Alpine Linux lands in `alpine:latest`.

For more info, read
#498 (comment)
apyrgio added a commit that referenced this issue Oct 2, 2023
This reverts commit 214ce97. The
rationale is that we want to wait until the LibreOffice package that
allows HWP conversion in Alpine Linux lands in `alpine:latest`.

For more info, read
#498 (comment)
apyrgio added a commit that referenced this issue Oct 2, 2023
This reverts commit acd615e. The
rationale is that we want to wait until the LibreOffice package that
allows HWP conversion in Alpine Linux lands in `alpine:latest`.

For more info, read
#498 (comment)
apyrgio added a commit that referenced this issue Oct 2, 2023
This reverts commit 214ce97. The
rationale is that we want to wait until the LibreOffice package that
allows HWP conversion in Alpine Linux lands in `alpine:latest`.

For more info, read
#498 (comment)
@OctopusET
Copy link
Contributor

OctopusET added a commit to OctopusET/dangerzone that referenced this issue Dec 8, 2023
This PR reverts the patch that disables HWP / HWPX conversion on MacOS M1.
It does not fix conversion on Qubes OS. freedomofpress#494

Previously, HWP / HWPX conversion didn't work on MacOS (Apple silicon CPU). freedomofpress#498
because libreoffice wasn't built with Java support on Alpine Linux for ARM (aarch64).

Gratefully, the Alpine team has enabled Java support on the aarch64
system [1], so we can enable it again for ARM architectures.
And this patch is included in Alpine 3.19

This commit was included in freedomofpress#541 and reverted on freedomofpress#562 due to a stability issue.

Fixes freedomofpress#498

[1]: https://gitlab.alpinelinux.org/alpine/aports/-/commit/74d443f479df15fc57e6fde6ac02a36b24afdded
@deeplow
Copy link
Contributor

deeplow commented Dec 8, 2023

Thank you very much pinging us about this and submitting a PR. We are just about to push out a security release, which should indeed include alpine 3.19. However, since it's a security-focused release and we had already hit feature-freeze, we will have to include your PR in the next one.

apyrgio pushed a commit to OctopusET/dangerzone that referenced this issue Dec 13, 2023
This PR reverts the patch that disables HWP / HWPX conversion on MacOS M1.
It does not fix conversion on Qubes OS (freedomofpress#494).

Previously, HWP / HWPX conversion didn't work on MacOS (Apple silicon CPU) (freedomofpress#498)
because libreoffice wasn't built with Java support on Alpine Linux for ARM (aarch64).

Gratefully, the Alpine team has enabled Java support on the aarch64
system [1], so we can enable it again for ARM architectures.
And this patch is included in Alpine 3.19

This commit was included in freedomofpress#541 and reverted on freedomofpress#562 due to a stability issue.

Fixes freedomofpress#498

[1]: https://gitlab.alpinelinux.org/alpine/aports/-/commit/74d443f479df15fc57e6fde6ac02a36b24afdded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants