Error file too long when sync windows file to linux with Chinese

Error file too long when sync windows file to Ubuntu server with 94 Chinese Chars

Support intro
On windows, it have one file named "4、一二三四项〔2016〕4号-关于加强一二三四五六七八有限公司大型设备(塔吊、施工升降机)管理及印发《2016年大型设备(塔吊、施工升降机及市政交通类)合格设备租赁商名录》的通知.txt"
When nextcloud sync to linux, From the the log it can see tips filename too long.
This name was valid on linux xfs/ext filesystem.

Also I follow the nextcloud php, the error tips by 
./lib/private/Files/Storage/Common.php		
        public function verifyPath($path, $fileName) {

Nextcloud version : nextcloud-20.0.2
Operating system and version: Ubuntu 20.04 LTS server
Apache or nginx version: Apache/2.4.41 (Ubuntu)
PHP version (eg, 7.1): 7.4.3

The issue you are facing:
As we know, the linux support max filename len was 255.
For Chinese, it should be 255/2, about 127. Actually, this file have only 94 Chinese Chars.
It tips Fatal error “文件名过长”, it means filename too long.
I also touch the filename on linux, it is OK.
lsheng@j1900:~$ touch 4、一二三四项〔2016〕4号-关于加强一二三四五六七八有限公司大型设备(塔吊、施工升降机)管理及印发《2016年大型设备(塔吊、施工升降机及市政交通类)合格设备租赁商名录》的通知.txt
lsheng@j1900:~$ ls -l 4、一二三四项〔2016〕4号-关于加强一二三四五六七八有限公司大型设备(塔吊、施工升降机)管理及印发《2016年大型设备(塔吊、施工升降机及市政交通类)合格设备租赁商名录》的通知.txt
-rw-rw-r-- 1 lsheng lsheng 0 Dec 8 10:40 4、一二三四项〔2016〕4号-关于加强一二三四五六七八有限公司大型设备(塔吊、施工升降机)管理及印发《2016年大型设备(塔吊、施工升降机及市政交通类)合格设备租赁商名录》的通知.txt
lsheng@j1900:~$
So it should not be xfs/ext filesystem issue.

lsheng@j1900:~$ getconf PATH_MAX /dev/sdb1
4096
lsheng@j1900:~$ getconf NAME_MAX /dev/sdb1
255

Is this the first time you’ve seen this error? (Y/N): Y

Steps to replicate it:

  1. On Windows, touch one file named with “4、一二三四项〔2016〕4号-关于加强一二三四五六七八有限公司大型设备(塔吊、施工升降机)管理及印发《2016年大型设备(塔吊、施工升降机及市政交通类)合格设备租赁商名录》的通知.txt” in the nextcloud sync folder
  2. On nextcloud with admin, choose the log, it can see the filename too long error in the log

The output of your Nextcloud log in Admin > Logging:

PASTE HERE

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'instanceid' => 'oc3lbh05cj59',
  'trusted_domains' => 
  array (
    0 => '127.0.0.1',
  ),
  'datadirectory' => '/data1/nextcloud',
  'dbtype' => 'mysql',
  'version' => '20.0.2.2',
  'overwrite.cli.url' => 'http://127.0.0.1/nextcloud',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost:3306',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'installed' => true,
);

The output of your Apache/nginx/system log in /var/log/____:
{“reqId”:“jd7hPxnWXqJtfSKnaXFL”,“level”:4,“time”:“2020-12-08T02:36:26+00:00”,“remoteAddr”:“118.113.15.65”,“user”:“lsheng”,“app”:“webdav”,“method”:“PUT”,“url”:"/nextcloud/remote.php/dav/files/lsheng/xxxxx/03doc/Gerneral/4%E3%80%81%E4%B8%80%E4%BA%8C%E4%B8%89%E5%9B%9B%E9%A1%B9%E3%80%942016%E3%80%954%E5%8F%B7-%E5%85%B3%E4%BA%8E%E5%8A%A0%E5%BC%BA%E4%B8%80%E4%BA%8C%E4%B8%89%E5%9B%9B%E4%BA%94%E5%85%AD%E4%B8%83%E5%85%AB%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8%E5%A4%A7%E5%9E%8B%E8%AE%BE%E5%A4%87%EF%BC%88%E5%A1%94%E5%90%8A%E3%80%81%E6%96%BD%E5%B7%A5%E5%8D%87%E9%99%8D%E6%9C%BA%EF%BC%89%E7%AE%A1%E7%90%86%E5%8F%8A%E5%8D%B0%E5%8F%91%E3%80%8A2016%E5%B9%B4%E5%A4%A7%E5%9E%8B%E8%AE%BE%E5%A4%87%EF%BC%88%E5%A1%94%E5%90%8A%E3%80%81%E6%96%BD%E5%B7%A5%E5%8D%87%E9%99%8D%E6%9C%BA%E5%8F%8A%E5%B8%82%E6%94%BF%E4%BA%A4%E9%80%9A%E7%B1%BB%EF%BC%89%E5%90%88%E6%A0%BC%E8%AE%BE%E5%A4%87%E7%A7%9F%E8%B5%81%E5%95%86%E5%90%8D%E5%BD%95%E3%80%8B%E7%9A%84%E9%80%9A%E7%9F%A5.txt",“message”:{“Exception”:“OCA\DAV\Connector\Sabre\Exception\InvalidPath”,“Message”:“文件名过长”,“Code”:0,“Trace”:[{“file”:"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Tree.php",“line”:80,“function”:“getChild”,“class”:“OCA\DAV\Connector\Sabre\Directory”,“type”:"->"},{“file”:"/var/www/nextcloud/apps/dav/lib/Connector/Sabre/LockPlugin.php",“line”:69,“function”:“getNodeForPath”,“class”:“Sabre\DAV\Tree”,“type”:"->"},{“file”:"/var/www/nextcloud/3rdparty/sabre/event/lib/WildcardEmitterTrait.php",“line”:89,“function”:“getLock”,“class”:“OCA\DAV\Connector\Sabre\LockPlugin”,“type”:"->"},{“file”:"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",“line”:458,“function”:“emit”,“class”:“Sabre\DAV\Server”,“type”:"->"},{“file”:"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",“line”:251,“function”:“invokeMethod”,“class”:“Sabre\DAV\Server”,“type”:"->"},{“file”:"/var/www/nextcloud/3rdparty/sabre/dav/lib/DAV/Server.php",“line”:319,“function”:“start”,“class”:“Sabre\DAV\Server”,“type”:"->"},{“file”:"/var/www/nextcloud/apps/dav/lib/Server.php",“line”:332,“function”:“exec”,“class”:“Sabre\DAV\Server”,“type”:"->"},{“file”:"/var/www/nextcloud/apps/dav/appinfo/v2/remote.php",“line”:35,“function”:“exec”,“class”:“OCA\DAV\Server”,“type”:"->"},{“file”:"/var/www/nextcloud/remote.php",“line”:167,“args”:["/var/www/nextcloud/apps/dav/appinfo/v2/remote.php"],“function”:“require_once”}],“File”:"/var/www/nextcloud/apps/dav/lib/Connector/Sabre/Directory.php",“Line”:226,“CustomMessage”:"–"},“userAgent”:“Mozilla/5.0 (Windows) mirall/3.0.2stable-Win64 (build 20200924) (Nextcloud)”,“version”:“20.0.2.2”,“id”:“5fcee6c72293f”}

This name is url encoded string. It can used online url decoder(https://meyerweb.com/eric/tools/dencoder/) to decode the string, the decoded string is “4、一二三四项〔2016〕4号-关于加强一二三四五六七八有限公司大型设备(塔吊、施工升降机)管理及印发《2016年大型设备(塔吊、施工升降机及市政交通类)合格设备租赁商名录》的通知.txt”

The decoded string was valid for ext/xfs filesystem path. I didn’t know how to uploaded the sample file.

./lib/private/Files/Storage/Common.php , the logic was handing on 544 line. I didn’t know whether the 255 string means url decoded string?
519 public function verifyPath($path, $fileName) {
520
521 // verify empty and dot files
522 $trimmed = trim($fileName);
523 if ($trimmed === ‘’) {
524 throw new EmptyFileNameException();
525 }
526
527 if (\OC\Files\Filesystem::isIgnoredDir($trimmed)) {
528 throw new InvalidDirectoryException();
529 }
530
531 if (!\OC::$server->getDatabaseConnection()->supports4ByteText()) {
532 // verify database - e.g. mysql only 3-byte chars
533 if (preg_match(’%(?:
534 \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
535 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
536 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
537 )%xs’, $fileName)) {
538 throw new InvalidCharacterInPathException();
539 }
540 }
541
542 // 255 characters is the limit on common file systems (ext/xfs)
543 // oc_filecache has a 250 char length limit for the filename
544 if (isset($fileName[250])) {
545 throw new FileNameTooLongException();
546 }
547
548 // NOTE: $path will remain unverified for now
549 $this->verifyPosixPath($fileName);
550 }