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

Command fails on UNC path containing spaces #83

Closed
thegoatherder opened this issue May 31, 2021 · 14 comments · Fixed by #165
Closed

Command fails on UNC path containing spaces #83

thegoatherder opened this issue May 31, 2021 · 14 comments · Fixed by #165
Labels
bug Something isn't working

Comments

@thegoatherder
Copy link

Describe the bug

Promise returns Command failed when the target filename is a windows UNC path containing spaces

To Reproduce

unRTF.convert('\\\\server\\some path\\to\\some document.rtf')

If I copy the unrtf command generated into the terminal and wrap the file path with " double quotes, the command succeeds.

@thegoatherder thegoatherder added the bug Something isn't working label May 31, 2021
@Fdawgs
Copy link
Owner

Fdawgs commented Jun 1, 2021

Thanks for reporting this @thegoatherder, I'll take a look!

@thegoatherder
Copy link
Author

thegoatherder commented Jun 1, 2021 via email

@Fdawgs
Copy link
Owner

Fdawgs commented Jun 1, 2021

Are you able to give the changes on the test/expand branch a try?

I've tested this locally (using Windows 10 and node v14.17.0, with Windows Server 2019 holding the test file) using the following and it's all ok:

const unRtf = new UnRTF();
const options = {
	noPictures: true,
	outputText: true,
};

const res = await unRtf.convert(
	"\\\\test-server\\c$\\test files\\test rtf simple whitespace.rtf",
	options
);

@thegoatherder
Copy link
Author

thegoatherder commented Jun 2, 2021 via email

@thegoatherder
Copy link
Author

@Fdawgs it's still not working for me. I ran node uninstall node-unrtf and then npm install Fdawgs/node-unrtf#test/expand to try out your branch.

I've noticed that the output command has changed now from using backslash paths to forward slash paths, which I believe should be cross-platform for bash/powershell (but not cmd prompt).

However, it still is failing. When I copy the command it is generating from the error object into a terminal, it still fails (tested in bash, powershell, windows cmd and node debug terminals).

If I take the same command and surround the path with quotes, it works immediately.

Input

const unRtf = new UnRTF();
const options = {
	noPictures: true,
	outputText: true,
};

const res = await unRtf.convert(
	"\\\\someserver\\p$\\Document Extract Second Run\\2016-08-19\\Some Folder/111111_250_0___11111111_person_201608191353502CO02_2.rtf.rtf",
	options
);

Output Error:

{"killed":false,"code":3221225477,"signal":null,"cmd":"G:/myproject/node_modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf --nopict --text //someserver/p$/Document Extract Second Run/2016-08-19/Some Folder/111111_250_0___11111111_person_201608191353502CO02_2.rtf.rtf","stdout":"","stderr":""}

Copy this command to a terminal and it fails:

G:/myproject/node_modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf --nopict --text //someserver/p$/Document Extract Second Run/2016-08-19/Some Folder/111111_250_0___11111111_person_201608191353502CO02_2.rtf.rtf

# Outputs:
# Usage: unrtf [--version] [--help] [--nopict|-n] [--html] [--text] [--vt] [--latex] [--ps] [--wpml] [-t html|text|vt|latex|ps|wpml] <filename>

Copy same command to a terminal and quote the target filename:

G:/myproject/node_modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf --nopict --text "//someserver/p$/Document Extract Second Run/2016-08-19/Some Folder/111111_250_0___11111111_person_201608191353502CO02_2.rtf.rtf"

... and it successfully extracts the text. Weird?

@thegoatherder
Copy link
Author

any ideas on this? Let me know if there's anything I can do to help, it's a major blocker for the project I'm working on.

@Fdawgs
Copy link
Owner

Fdawgs commented Jun 6, 2021

@thegoatherder Going to revisit it tomorrow. 😊

@thegoatherder
Copy link
Author

@Fdawgs Apologies, but I'm starting to think my bug report may have been in error. I have just spent some more time testing both the master and test/expand branches. I've found that even paths without spaces are failing. I'm wondering if it might be a permissions/security issue...? When I copy and run the cmd: in the error object (see below), it works in a powershell terminal (so long as the path doesn't have spaces). If the path does have spaces, I can get it to work by quoting the path. In any case, I'm seeing errors even on simple UNC paths.

Could it be that the unrtf.exe file is being run with a different user credential than the parent node application? If so do you have any idea which user I need to give permissions to on the folder? My app is also using other libs like pdf-parse and docx-extractor but I don't think these are using an execFile like your is...


Error: Command failed: G:/myproject/node_modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf --nopict --text "//someserver/p$/Document Extract Second Run/2016-08-19/Letters/43298809_250_0___41635197_Brefo_201608191516502CO02_2.rtf.rtf"
This is UnRTF, version 0.19.3
By Dave Davey and Marcos Serrou do Amaral
Original Author: Zach T. Smith
Error: cannot open input file

    at ChildProcess.exithandler (child_process.js:308:12)
    at ChildProcess.emit (events.js:315:20)
    at maybeClose (internal/child_process.js:1048:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5) {
  killed: false,
  code: 10,
  signal: null,
  cmd: 'G:/myproject/node_modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf --nopict --text "//someserver/p$/Document Extract Second Run/2016-08-19/Letters/43298809_250_0___41635197_Brefo_201608191516502CO02_2.rtf.rtf"',
  stdout: '',
  stderr: 'This is UnRTF, version 0.19.3\r\n' +
    'By Dave Davey and Marcos Serrou do Amaral\r\n' +
    'Original Author: Zach T. Smith\r\n' +
    'Error: cannot open input file\r\n'
}
FAIL: \\someserver\p$\Document Extract Second Run\2016-08-19\Letters\43298809_250_0___41635197_Brefo_201608191516502CO02_2.rtf.rtf
Error: Command failed: G:/myproject/node_modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf --nopict --text "//someserver/p$/Document Extract Second Run/2016-08-19/Letters/43298809_250_0___41635197_Brefo_201608191516502CO02_2.rtf.rtf"
This is UnRTF, version 0.19.3
By Dave Davey and Marcos Serrou do Amaral
Original Author: Zach T. Smith
Error: cannot open input file

    at ChildProcess.exithandler (child_process.js:308:12)
    at ChildProcess.emit (events.js:315:20)
    at maybeClose (internal/child_process.js:1048:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5) {
  killed: false,
  code: 10,
  signal: null,
  cmd: 'G:/myproject/node_modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf --nopict --text "//someserver/p$/Document Extract Second Run/2016-08-19/Letters/43298809_250_0___41635197_Brefo_201608191516502CO02_2.rtf.rtf"',
  stdout: '',
  stderr: 'This is UnRTF, version 0.19.3\r\n' +
    'By Dave Davey and Marcos Serrou do Amaral\r\n' +
    'Original Author: Zach T. Smith\r\n' +
    'Error: cannot open input file\r\n'
}
FAIL: //someserver/p$/Document Extract Second Run/2016-08-19/Letters/43298809_250_0___41635197_Brefo_201608191516502CO02_2.rtf.rtf
Error: Command failed: G:/myproject/node_modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf --nopict --text "//someserver/p$/TestDocExtract/2016-08-19/Letters/43298809_250_0___41635197_Brefo_201608191516502CO02_2.rtf.rtf"
This is UnRTF, version 0.19.3
By Dave Davey and Marcos Serrou do Amaral
Original Author: Zach T. Smith
Error: cannot open input file

    at ChildProcess.exithandler (child_process.js:308:12)
    at ChildProcess.emit (events.js:315:20)
    at maybeClose (internal/child_process.js:1048:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5) {
  killed: false,
  code: 10,
  signal: null,
  cmd: 'G:/myproject/node_modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf --nopict --text "//someserver/p$/TestDocExtract/2016-08-19/Letters/43298809_250_0___41635197_Brefo_201608191516502CO02_2.rtf.rtf"',
  stdout: '',
  stderr: 'This is UnRTF, version 0.19.3\r\n' +
    'By Dave Davey and Marcos Serrou do Amaral\r\n' +
    'Original Author: Zach T. Smith\r\n' +
    'Error: cannot open input file\r\n'
}
FAIL: \\someserver\p$\TestDocExtract\2016-08-19\Letters\43298809_250_0___41635197_Brefo_201608191516502CO02_2.rtf.rtf
Error: Command failed: G:/myproject/node_modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf --nopict --text "//someserver/p$/TestDocExtract/2016-08-19/Letters/43298809_250_0___41635197_Brefo_201608191516502CO02_2.rtf.rtf"
This is UnRTF, version 0.19.3
By Dave Davey and Marcos Serrou do Amaral
Original Author: Zach T. Smith
Error: cannot open input file

    at ChildProcess.exithandler (child_process.js:308:12)
    at ChildProcess.emit (events.js:315:20)
    at maybeClose (internal/child_process.js:1048:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5) {
  killed: false,
  code: 10,
  signal: null,
  cmd: 'G:/myproject/node_modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf --nopict --text "//someserver/p$/TestDocExtract/2016-08-19/Letters/43298809_250_0___41635197_Brefo_201608191516502CO02_2.rtf.rtf"',
  stdout: '',
  stderr: 'This is UnRTF, version 0.19.3\r\n' +
    'By Dave Davey and Marcos Serrou do Amaral\r\n' +
    'Original Author: Zach T. Smith\r\n' +
    'Error: cannot open input file\r\n'
}
FAIL: //someserver/p$/TestDocExtract/2016-08-19/Letters/43298809_250_0___41635197_Brefo_201608191516502CO02_2.rtf.rtf
Error: Command failed: G:/myproject/node_modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf --nopict --text "//someserver/p$/TestDocExtract/2016-08-19/Letters/test.rtf"
This is UnRTF, version 0.19.3
By Dave Davey and Marcos Serrou do Amaral
Original Author: Zach T. Smith
Error: cannot open input file

    at ChildProcess.exithandler (child_process.js:308:12)
    at ChildProcess.emit (events.js:315:20)
    at maybeClose (internal/child_process.js:1048:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5) {
  killed: false,
  code: 10,
  signal: null,
  cmd: 'G:/myproject/node_modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf --nopict --text "//someserver/p$/TestDocExtract/2016-08-19/Letters/test.rtf"',
  stdout: '',
  stderr: 'This is UnRTF, version 0.19.3\r\n' +
    'By Dave Davey and Marcos Serrou do Amaral\r\n' +
    'Original Author: Zach T. Smith\r\n' +
    'Error: cannot open input file\r\n'
}
FAIL: \\someserver\p$\TestDocExtract\2016-08-19\Letters\test.rtf
Error: Command failed: G:/myproject/node_modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf --nopict --text "//someserver/p$/TestDocExtract/2016-08-19/Letters/test.rtf"
This is UnRTF, version 0.19.3
By Dave Davey and Marcos Serrou do Amaral
Original Author: Zach T. Smith
Error: cannot open input file

    at ChildProcess.exithandler (child_process.js:308:12)
    at ChildProcess.emit (events.js:315:20)
    at maybeClose (internal/child_process.js:1048:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5) {
  killed: false,
  code: 10,
  signal: null,
  cmd: 'G:/myproject/node_modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf --nopict --text "//someserver/p$/TestDocExtract/2016-08-19/Letters/test.rtf"',
  stdout: '',
  stderr: 'This is UnRTF, version 0.19.3\r\n' +
    'By Dave Davey and Marcos Serrou do Amaral\r\n' +
    'Original Author: Zach T. Smith\r\n' +
    'Error: cannot open input file\r\n'
}
FAIL: //someserver/p$/TestDocExtract/2016-08-19/Letters/test.rtf
Error: Command failed: G:/myproject/node_modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf --nopict --text "//someserver/p$/TestDocExtract/20160819/Letters/test.rtf"
This is UnRTF, version 0.19.3
By Dave Davey and Marcos Serrou do Amaral
Original Author: Zach T. Smith
Error: cannot open input file

    at ChildProcess.exithandler (child_process.js:308:12)
    at ChildProcess.emit (events.js:315:20)
    at maybeClose (internal/child_process.js:1048:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5) {
  killed: false,
  code: 10,
  signal: null,
  cmd: 'G:/myproject/node_modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf --nopict --text "//someserver/p$/TestDocExtract/20160819/Letters/test.rtf"',
  stdout: '',
  stderr: 'This is UnRTF, version 0.19.3\r\n' +
    'By Dave Davey and Marcos Serrou do Amaral\r\n' +
    'Original Author: Zach T. Smith\r\n' +
    'Error: cannot open input file\r\n'
}
FAIL: \\someserver\p$\TestDocExtract\20160819\Letters\test.rtf
Error: Command failed: G:/myproject/node_modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf --nopict --text "//someserver/p$/TestDocExtract/20160819/Letters/test.rtf"
This is UnRTF, version 0.19.3
By Dave Davey and Marcos Serrou do Amaral
Original Author: Zach T. Smith
Error: cannot open input file

    at ChildProcess.exithandler (child_process.js:308:12)
    at ChildProcess.emit (events.js:315:20)
    at maybeClose (internal/child_process.js:1048:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:288:5) {
  killed: false,
  code: 10,
  signal: null,
  cmd: 'G:/myproject/node_modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf --nopict --text "//someserver/p$/TestDocExtract/20160819/Letters/test.rtf"',
  stdout: '',
  stderr: 'This is UnRTF, version 0.19.3\r\n' +
    'By Dave Davey and Marcos Serrou do Amaral\r\n' +
    'Original Author: Zach T. Smith\r\n' +
    'Error: cannot open input file\r\n'
}
FAIL: //someserver/p$/TestDocExtract/20160819/Letters/test.rtf

@thegoatherder
Copy link
Author

thegoatherder commented Jun 7, 2021

@Fdawgs i tried some more stuff last night, it didn’t work, but here are some notes:

  • added “everyone” to folder with full rights in security - no difference. Tried the same for some system accounts, no difference.
  • started playing with your code:
  • I noticed that you’re using child_process.execFile() instead of exec(). This has known limited capabilities with paths and globs etc. Tried exec() instead (with args.join(‘ ‘)) - didn’t work
  • Checked process.env.ComSpec and realised child process default shell is cmd.exe (which doesn’t support forward slashes in paths). Changed to powershell on my local - didn’t work.
  • Ensured that the —text variable gets wrapped in quote marks - this did work in that if I copy any command output by exec file or exec into powershell then it works without any further changes. But it still doesn’t work when called from node.js
  • Screamed and roared a bit. Howled at the moon. Didn’t work

If you have any ideas I’m all ears. My gut says it’s 50% likely to be a security thing, 50% something else. It’s also telling me to stop being stupid and just run Docker! Do you run Docker Desktop on top of windows server? Or are you using Docker Enterprise or Docker on Linux? Is Docker Desktop on Windows Server good enough for production use?

@Fdawgs
Copy link
Owner

Fdawgs commented Jun 7, 2021

@thegoatherder After further investigation, I believe it may be down to the version of UnRTF and the RTF spec supported.

UnRTF v0.19.3 (which is included with this module for Windows) was released in 2004, when v1.8 of the RTF specification was standard.
I've been testing this module using old RTFs that predate 2004. 🤦

RTF v1.9 was released in 2007, and MS Word 2007 onwards saves new RTFs using v1.9.1.
If I attempt to use an RTF generated from MS Word 2016 for example, node-unrtf throws the same Command Failed errors you see!

If i send the same document generated from MS Word 2016 to Docsmith (which uses UnRTF v0.21.10 when ran under Docker), the document converts fine!

I would suggest running your application under Docker to get the latest version of UnRTF.
I haven't tried running Docker Desktop on Windows Server, so can't comment, though it seems fine on a personal Windows machine!

I will add a note to the documentation regarding the use of the included UnRTF binary and it only being able to handle RTFs up to v1.8

@thegoatherder
Copy link
Author

@Fdawgs This theory doesn’t explain why copying the command from the UnRTF error object returned by node.js works when pasted into a powershell window... the same command extracts text to the terminal without error...

@Fdawgs
Copy link
Owner

Fdawgs commented Jun 7, 2021

From what I can see, Node watches the error code and if it's not 0 then throws Command Failed error.

So, if i run one of these old files in the command line:

$ C:/Repositories/public/modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf C:/Repositories/public/modules/node-unrtf/test_files/test-rtf-simple.rtf && echo $?
Processing C:/Repositories/public/modules/node-unrtf/test_files/test-rtf-simple.rtf...
<html>
<head>
<!--- Translation from RTF performed by UnRTF, version 0.19.3 --->
<!--- For information about this marvellous program, --->
<!--- please go to http://www.gnu.org/software/unrtf/unrtf.html --->
<!--- document uses ANSI character set --->
<!--- font table contains 8 fonts total --->
<!--- creaton date: 2 July 2020 19:05  --->
<!--- revision date: 2 July 2020 19:05  --->
<!--- last printed:  --->
</head>
<body><font color="#000000"><font face="Liberation Serif"><font size=3></font></font></font><font color="#000000"><font face="Liberation Serif"><font size=3>Ask not what your country can do for you, ask what you can do for your country.</font></font></font><font color="#000000"><font face="Liberation Serif"><font size=3><br>
</font></font></font></body>
</html>
Done.
174 words were hashed.
0 <--- error code

And if i run one of the newer RTFs:

$ C:/Repositories/public/modules/node-unrtf/src/lib/win32/unrtf-0.19.3/bin/unrtf C:/Repositories/public/modules/node-unrtf/test_files/Testr2.rtf && echo $?
This is UnRTF, version 0.19.3
By Dave Davey and Marcos Serrou do Amaral
Original Author: Zach T. Smith
Processing C:/Repositories/public/modules/node-unrtf/test_files/Testr2.rtf...
<html>
<head>
<!--- Translation from RTF performed by UnRTF, version 0.19.3 --->
<!--- For information about this marvellous program, --->
<!--- please go to http://www.gnu.org/software/unrtf/unrtf.html --->
<!--- document uses ANSI character set --->
<!--- font table contains 99 fonts total --->
<!--author: Frazer Smith--->
<!--- creaton date: 7 June 2021 10:19  --->
<!--- revision date: 7 June 2021 10:20  --->
<!--- total pages: 1 --->
<!--- total words: 1 --->
<!--- total chars: 6 --->
<!--- invalid font number 31506 --->
</head>
<body><span style="font-size:11pt"></span><span style="font-size:11pt">Testr2</span><span style="font-size:11pt"></span><span style="font-size:11pt"><br>
</span><span style="font-size:11pt"></span><span style="font-size:11pt"></span><span style="font-size:11pt"></span><span style="font-size:11pt"></span><span style="font-size:11pt"></span><span style="font-size:11pt"></span><span style="font-size:11pt"></span><span style="font-size:11pt"></span><span style="font-size:11pt"></span>Segmentation fault
139 <--- error code

When you've tested your documents in the command line, does it generate the document but also throw up some sort of text to indicate there may be something wrong? Looking at the one above, it has the Segmentation fault and invalid font number 31506.

@Fdawgs
Copy link
Owner

Fdawgs commented Jun 22, 2021

Afternoon @thegoatherder, have you had the chance to retest this? 😸

@thegoatherder
Copy link
Author

thegoatherder commented Jun 22, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants