icewind1991 / SMB

PHP wrapper for smbclient
MIT License
136 stars 54 forks source link

Can't upload .pdf or .docx on 12.0.3 version to a smb external storage #63

Open upmferraz opened 6 years ago

upmferraz commented 6 years ago

Hi, we’re getting some issues on uploading .pdf or .docx to a cifs external storage using icewind smb that’s being used as a group area in nextcloud.

Still getting the same behaviour using the packed version on Nextcloud 12.0.4 and now in 12.0.5 After substituting the smb backend from version 11 the problem disappears

Getting the following in logs:

{"reqId":"3S7H3Rfm3Flkmqiu98jz","level":3,"time":"2018-01-25T11:25:21+00:00","remoteAddr":"193.137.54.7","user":"241409","app":"remote","method":"PUT","url":"/remote.php/webdav/Groups/ASU/Meltdown_Spectre/PsExec.exe","message":"Exception: {"Exception":"Error","Message":"Class '\Icewind\SMB\Exception\InvalidArgumentException' not found","Code":0,"Trace":"#0 \/ocdata\/html\/apps\/files_external\/3rdparty\/icewind\/smb\/src\/NativeState.php(49): Icewind\SMB\Exception\Exception::fromMap(Array, 22, NULL)\n#1 \/ocdata\/html\/apps\/files_external\/3rdparty\/icewind\/smb\/src\/NativeState.php(61): Icewind\SMB\NativeState->handleError(NULL)\n#2 \/ocdata\/html\/apps\/files_external\/3rdparty\/icewind\/smb\/src\/NativeState.php(231): Icewind\SMB\NativeState->testResult(false, Resource id #14)\n#3 \/ocdata\/html\/apps\/files_external\/3rdparty\/icewind\/smb\/src\/NativeWriteStream.php(65): Icewind\SMB\NativeState->write(Resource id #14, 'MZ\x90\x00\x03\x00\x00\x00\x04\x00\x00\x00\xFF\xFF\x00...')\n#4 \/ocdata\/html\/apps\/files_external\/3rdparty\/icewind\/smb\/src\/NativeWriteStream.php(83): Icewind\SMB\NativeWriteStream->flushWrite()\n#5 [internal function]: Icewind\SMB\NativeWriteStream->stream_close()\n#6 \/ocdata\/html\/apps\/files_external\/3rdparty\/icewind\/streams\/src\/Wrapper.php(124): fclose(Resource id #18)\n#7 \/ocdata\/html\/apps\/files_external\/3rdparty\/icewind\/streams\/src\/CallbackWrapper.php(107): Icewind\Streams\Wrapper->stream_close()\n#8 [internal function]: Icewind\Streams\CallbackWrapper->stream_close()\n#9 \/ocdata\/html\/apps\/dav\/lib\/Connector\/Sabre\/File.php(135): fclose(Resource id #21)\n#10 \/ocdata\/html\/apps\/dav\/lib\/Connector\/Sabre\/Directory.php(151): OCA\DAV\Connector\Sabre\File->put(Resource id #12)\n#11 \/ocdata\/html\/3rdparty\/sabre\/dav\/lib\/DAV\/Server.php(1096): OCA\DAV\Connector\Sabre\Directory->createFile('PsExec.exe', Resource id #12)\n#12 \/ocdata\/html\/3rdparty\/sabre\/dav\/lib\/DAV\/CorePlugin.php(525): Sabre\DAV\Server->createFile('Groups\/ASU\/Melt...', Resource id #12, NULL)\n#13 [internal function]: Sabre\DAV\CorePlugin->httpPut(Object(Sabre\HTTP\Request), Object(Sabre\HTTP\Response))\n#14 \/ocdata\/html\/3rdparty\/sabre\/event\/lib\/EventEmitterTrait.php(105): call_user_func_array(Array, Array)\n#15 \/ocdata\/html\/3rdparty\/sabre\/dav\/lib\/DAV\/Server.php(479): Sabre\Event\EventEmitter->emit('method:PUT', Array)\n#16 \/ocdata\/html\/3rdparty\/sabre\/dav\/lib\/DAV\/Server.php(254): Sabre\DAV\Server->invokeMethod(Object(Sabre\HTTP\Request), Object(Sabre\HTTP\Response))\n#17 \/ocdata\/html\/apps\/dav\/appinfo\/v1\/webdav.php(76): Sabre\DAV\Server->exec()\n#18 \/ocdata\/html\/remote.php(162): require_once('\/ocdata\/html\/ap...')\n#19 {main}","File":"\/ocdata\/html\/apps\/files_external\/3rdparty\/icewind\/smb\/src\/Exception\/Exception.php","Line":30}","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36","version":"12.0.5.3"}

ynott commented 6 years ago

12.0.2 version and that solved the problem.

ynott commented 6 years ago

part file exist on CIFS server.

-rwxr-xr-x 1 root root       0  3月  7 10:30 100MB.txt.ocTransferId2111567979.part
-rwxr-xr-x 1 root root       0  3月  7 10:30 100MB.txt.ocTransferId329974771.part

This is log Messages on nextcloud.log

{"reqId":"FyDtmAiwZXYHsSODllg6","level":3,"time":"2018-03-07 13:16:01","remoteAddr":"xx.xx.xx.xx","user":"testxxxxxxx","app":"PHP","method":"PUT","url":"\/remote.php\/webdav\/100MB.txt","message":"include(\/var\/www\/html\/nextcloud\/apps\/files_external\/3rdparty\/composer\/..\/icewind\/smb\/src\/Exception\/InvalidArgumentException.php): failed to open stream: No such file or directory at \/var\/www\/html\/nextcloud\/lib\/composer\/composer\/ClassLoader.php#444","userAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/66.0.3355.0 Safari\/537.36","version":"12.0.5.3"} {"reqId":"FyDtmAiwZXYHsSODllg6","level":3,"time":"2018-03-07 13:16:01","remoteAddr":"xx.xx.xx.xx","user":"testxxxxxxx","app":"PHP","method":"PUT","url":"\/remote.php\/webdav\/100MB.txt","message":"include(): Failed opening '\/var\/www\/html\/nextcloud\/apps\/files_external\/3rdparty\/composer\/..\/icewind\/smb\/src\/Exception\/InvalidArgumentException.php' for inclusion (include_path='\/var\/www\/html\/nextcloud\/3rdparty\/pear\/console_getopt:\/var\/www\/html\/nextcloud\/3rdparty\/pear\/pear_exception:\/var\/www\/html\/nextcloud\/3rdparty\/pear\/archive_tar:\/var\/www\/html\/nextcloud\/3rdparty\/pear\/pear-core-minimal\/src:\/var\/www\/html\/nextcloud\/apps') at \/var\/www\/html\/nextcloud\/lib\/composer\/composer\/ClassLoader.php#444","userAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/66.0.3355.0 Safari\/537.36","version":"12.0.5.3"} {"reqId":"FyDtmAiwZXYHsSODllg6","level":3,"time":"2018-03-07 13:16:01","remoteAddr":"xx.xx.xx.xx","user":"testxxxxxxx","app":"remote","method":"PUT","url":"\/remote.php\/webdav\/100MB.txt","message":"Exception: {\"Exception\":\"Error\",\"Message\":\"Class '\\Icewind\\SMB\\Exception\\InvalidArgumentException' not found\",\"Code\":0,\"Trace\":\"#0 \\/var\\/www\\/html\\/nextcloud\\/apps\\/files_external\\/3rdparty\\/icewind\\/smb\\/src\\/NativeState.php(49): Icewind\\SMB\\Exception\\Exception::fromMap(Array, 22, NULL)\n#1 \\/var\\/www\\/html\\/nextcloud\\/apps\\/files_external\\/3rdparty\\/icewind\\/smb\\/src\\/NativeState.php(61): Icewind\\SMB\\NativeState->handleError(NULL)\n#2 \\/var\\/www\\/html\\/nextcloud\\/apps\\/files_external\\/3rdparty\\/icewind\\/smb\\/src\\/NativeState.php(231): Icewind\\SMB\\NativeState->testResult(false, Resource id #37)\n#3 \\/var\\/www\\/html\\/nextcloud\\/apps\\/files_external\\/3rdparty\\/icewind\\/smb\\/src\\/NativeWriteStream.php(65): Icewind\\SMB\\NativeState->write(Resource id #37, '\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00...')\n#4 \\/var\\/www\\/html\\/nextcloud\\/apps\\/files_external\\/3rdparty\\/icewind\\/smb\\/src\\/NativeWriteStream.php(76): Icewind\\SMB\\NativeWriteStream->flushWrite()\n#5 [internal function]: Icewind\\SMB\\NativeWriteStream->stream_write('\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00...')\n#6 \\/var\\/www\\/html\\/nextcloud\\/apps\\/files_external\\/3rdparty\\/icewind\\/streams\\/src\\/Wrapper.php(87): fwrite(Resource id #44, '\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00...')\n#7 \\/var\\/www\\/html\\/nextcloud\\/apps\\/files_external\\/3rdparty\\/icewind\\/streams\\/src\\/CallbackWrapper.php(99): Icewind\\Streams\\Wrapper->stream_write('\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00...')\n#8 [internal function]: Icewind\\Streams\\CallbackWrapper->stream_write('\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00...')\n#9 \\/var\\/www\\/html\\/nextcloud\\/lib\\/private\\/legacy\\/helper.php(297): fwrite(Resource id #50, '\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00...')\n#10 \\/var\\/www\\/html\\/nextcloud\\/apps\\/dav\\/lib\\/Connector\\/Sabre\\/File.php(134): OC_Helper::streamCopy(Resource id #27, Resource id #50)\n#11 \\/var\\/www\\/html\\/nextcloud\\/apps\\/dav\\/lib\\/Connector\\/Sabre\\/Directory.php(151): OCA\\DAV\\Connector\\Sabre\\File->put(Resource id #27)\n#12 \\/var\\/www\\/html\\/nextcloud\\/3rdparty\\/sabre\\/dav\\/lib\\/DAV\\/Server.php(1096): OCA\\DAV\\Connector\\Sabre\\Directory->createFile('100MB.txt', Resource id #27)\n#13 \\/var\\/www\\/html\\/nextcloud\\/3rdparty\\/sabre\\/dav\\/lib\\/DAV\\/CorePlugin.php(525): Sabre\\DAV\\Server->createFile('100MB.txt', Resource id #27, NULL)\n#14 [internal function]: Sabre\\DAV\\CorePlugin->httpPut(Object(Sabre\\HTTP\\Request), Object(Sabre\\HTTP\\Response))\n#15\\/var\\/www\\/html\\/nextcloud\\/3rdparty\\/sabre\\/event\\/lib\\/EventEmitterTrait.php(105): call_user_func_array(Array, Array)\n#16 \\/var\\/www\\/html\\/nextcloud\\/3rdparty\\/sabre\\/dav\\/lib\\/DAV\\/Server.php(479): Sabre\\Event\\EventEmitter->emit('method:PUT', Array)\n#17 \\/var\\/www\\/html\\/nextcloud\\/3rdparty\\/sabre\\/dav\\/lib\\/DAV\\/Server.php(254): Sabre\\DAV\\Server->invokeMethod(Object(Sabre\\HTTP\\Request), Object(Sabre\\HTTP\\Response))\n#18 \\/var\\/www\\/html\\/nextcloud\\/apps\\/dav\\/appinfo\\/v1\\/webdav.php(76): Sabre\\DAV\\Server->exec()\n#19 \\/var\\/www\\/html\\/nextcloud\\/remote.php(162): require_once('\\/var\\/www\\/html\\/n...')\n#20 {main}\",\"File\":\"\\/var\\/www\\/html\\/nextcloud\\/apps\\/files_external\\/3rdparty\\/icewind\\/smb\\/src\\/Exception\\/Exception.php\",\"Line\":30}","userAgent":"Mozilla\/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit\/537.36 (KHTML, like Gecko) Chrome\/66.0.3355.0 Safari\/537.36","version":"12.0.5.3"}

ynott commented 6 years ago

@icewind1991 I found "InvalidArgumentException.php" on https://github.com/icewind1991/SMB/blob/v2.0.4/src/Exception/InvalidArgumentException.php But https://github.com/nextcloud/server/tree/v12.0.5/apps/files_external/3rdparty/icewind/smb/src/Exception is not.

Is this a packaging mistake?

scarmic commented 6 years ago

Same issue for me. Nextcloud version 14.0.1. It seems it depends of some type of files, such some docx files. The same file, opened with libreoffice and then saved, doesn't have the same issue.