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

Save as does not work: iconv doesn't support UTF-7 on Alpine #1966

Closed
Keessaus opened this issue Jan 7, 2022 · 0 comments · Fixed by #1967
Closed

Save as does not work: iconv doesn't support UTF-7 on Alpine #1966

Keessaus opened this issue Jan 7, 2022 · 0 comments · Fixed by #1967

Comments

@Keessaus
Copy link
Contributor

Keessaus commented Jan 7, 2022

At the end of this description, a possible solution is proposed.

Symptoms

Describe the bug
The function Save as from any richdocuments editor does not work as intended on Alpine PHP containers. A copy of the file is saved, not with the input name, but in the format (#) with # a number that is not yet used in that folder. If saving is successful, the current file in the editor changes to the saved as file, but not with this bug.

To Reproduce
Steps to reproduce the behavior:

  1. Edit a document
  2. Click Save as under menu tab File
  3. Enter a name of choice and press save
  4. Be greeted by an error pop-up stating:

    The document can't be saved to storage. Check your permissions or contact the storage server administrator.

Expected behavior
The file is saved as the name as input, and the editing of the program continues in this new saved as file.

Client details:
Problem occurs on multiple devices, in multiple browsers (Firefox on Ubuntu, Chromium on Ubuntu, Firefox on Windows 10, Chrome on Windows 10).

Server details

Operating system: Docker container fpm-alpine-production (currently alias for 22.2.3-fpm-alpine)
Web server: Nginx
Database: mariadb
PHP version: 8.0
Nextcloud version: 22.2.3
Version of the richdocuments app: 4.2.3
Version of Collabora Online: 21.06.10.1

Logs

Nextcloud log (from /settings/admin/logging)

{
  "reqId": "4k5yAIC5CWSKEBX9iCeA",
  "level": 3,
  "time": "2022-01-05T18:00:31+00:00",
  "remoteAddr": "172.22.7.1",
  "user": "--",
  "app": "PHP",
  "method": "POST",
  "url": "/index.php/apps/richdocuments/wopi/files/127314_oc19872ox31u?access_token=areTokensPrivateInformation&access_token_ttl=0",
  "message": "iconv(): Wrong encoding, conversion from "utf-7" to "utf-8" is not allowed at /var/www/html/custom_apps/richdocuments/lib/Controller/WopiController.php#611",
  "userAgent": "COOLWSD HTTP Agent 21.11.0.6",
  "version": "22.2.3.0",
  "exception": {
    "Exception": "Error",
    "Message": "iconv(): Wrong encoding, conversion from "utf-7" to "utf-8" is not allowed at /var/www/html/custom_apps/richdocuments/lib/Controller/WopiController.php#611",
    "Code": 0,
    "Trace": [
      {
        "function": "onError",
        "class": "OC\\Log\\ErrorHandler",
        "type": "::",
        "args": [
          2,
          "iconv(): Wrong encoding, conversion from "utf-7" to "utf-8" is not allowed",
          "/var/www/html/custom_apps/richdocuments/lib/Controller/WopiController.php",
          611
        ]
      },
      {
        "file": "/var/www/html/custom_apps/richdocuments/lib/Controller/WopiController.php",
        "line": 611,
        "function": "iconv",
        "args": [
          "utf-7",
          "utf-8",
          "myPrettyNewFileNameAsExample.odt"
        ]
      },
      {
        "file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 217,
        "function": "putRelativeFile",
        "class": "OCA\\Richdocuments\\Controller\\WopiController",
        "type": "->",
        "args": [
          "127314",
          "areTokensPrivateInformation"
        ]
      },
      {
        "file": "/var/www/html/lib/private/AppFramework/Http/Dispatcher.php",
        "line": 126,
        "function": "executeController",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->",
        "args": [
          {
            "__class__": "OCA\\Richdocuments\\Controller\\WopiController"
          },
          "putRelativeFile"
        ]
      },
      {
        "file": "/var/www/html/lib/private/AppFramework/App.php",
        "line": 156,
        "function": "dispatch",
        "class": "OC\\AppFramework\\Http\\Dispatcher",
        "type": "->",
        "args": [
          {
            "__class__": "OCA\\Richdocuments\\Controller\\WopiController"
          },
          "putRelativeFile"
        ]
      },
      {
        "file": "/var/www/html/lib/private/Route/Router.php",
        "line": 301,
        "function": "main",
        "class": "OC\\AppFramework\\App",
        "type": "::",
        "args": [
          "OCA\\Richdocuments\\Controller\\WopiController",
          "putRelativeFile",
          {
            "__class__": "OC\\AppFramework\\DependencyInjection\\DIContainer"
          },
          {
            "fileId": "127314_oc19872ox31u",
            "_route": "richdocuments.wopi.putRelativeFile"
          }
        ]
      },
      {
        "file": "/var/www/html/lib/base.php",
        "line": 1000,
        "function": "match",
        "class": "OC\\Route\\Router",
        "type": "->",
        "args": [
          "/apps/richdocuments/wopi/files/127314_oc19872ox31u"
        ]
      },
      {
        "file": "/var/www/html/index.php",
        "line": 36,
        "function": "handleRequest",
        "class": "OC",
        "type": "::",
        "args": []
      }
    ],
    "File": "/var/www/html/lib/private/Log/ErrorHandler.php",
    "Line": 92,
    "CustomMessage": "--"
  },
  "id": "61d80d0b492f6"
}

Workaround and solution

After some tiring research, I found out iconv on my PHP-FPM Alpine container does not support the UTF-7 encoding in the Alpine PHP container.

iconv -l
UTF-8, UTF-16BE, UTF-16LE, UTF-32BE, UTF32-LE, UCS-2BE, UCS-2LE, WCHAR_T,
US_ASCII, ISO8859-1, ISO8859-2, ISO8859-3, ISO8859-4, ISO8859-5,
ISO8859-6, ISO8859-7, ...

The Nextcloud Mail app also had an issue with limited iconv support, see nextcloud/mail#4351. Their solution was to avoid using these missing features. The missing features are part of the official PHP-FPM Alpine container upon which the official Nextcloud PHP-FPM Alpine container is based. This would arise from using musl (instead of glibc), and the limitations are well noted by the musl docs, which implies no intention to change this.

The issue is also discussed in the docker-library/php project. A currently working workaround is proposed in docker-library/php#240 (comment).

As a long-term solution, I propose switching from iconv to mb_convert_encoding, as it has the UTF-7 encoding (and more) support built-in, and mbstring is quite standard (and already used by Nextcloud Server). I will submit a PR shortly.

Keessaus added a commit to Keessaus/richdocuments that referenced this issue Jan 7, 2022
backportbot-nextcloud bot pushed a commit that referenced this issue Jan 10, 2022
backportbot-nextcloud bot pushed a commit that referenced this issue Jan 10, 2022
Raudius pushed a commit that referenced this issue Jul 27, 2022
Fixes #1966

Signed-off-by: Kees van Kempen <[email protected]>
Signed-off-by: Raul <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant