Bug 120249 - CLI: cannot use a path with trailing backslash on Windows
Summary: CLI: cannot use a path with trailing backslash on Windows
Status: CLOSED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: UI (show other bugs)
Version:
(earliest affected)
3.4.0 release
Hardware: All Windows (All)
: medium normal
Assignee: Mike Kaganski
URL:
Whiteboard: target:6.2.0 target:6.1.3
Keywords:
Depends on:
Blocks:
 
Reported: 2018-10-01 18:31 UTC by Mike Kaganski
Modified: 2020-04-23 08:41 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Kaganski 2018-10-01 18:31:51 UTC
The command line like

> soffice.exe --convert-to pdf path-to-file.odt --outdir c:\test\
or
> soffice.exe --convert-to pdf --outdir c:\test\ path-to-file.odt


fails to produce the output file in the specified directory; while

> soffice.exe --convert-to pdf path-to-file.odt --outdir c:\test

works fine (note the trailing backslash in the outdir path in the first case). Also

> soffice.exe --convert-to pdf path-to-file.odt --outdir c:/test/

works.

The problem is that soffice.exe processes its command line arguments, and passes them to the spawned soffice.bin process quoted in double-quotes; it appends -env:OOO_CWD=... to the end of the resulting command line. So, the resulting soffice.bin command line in the first case would be

> "soffice.bin" "--convert-to" "pdf" "path-to-file.odt" "--outdir" "c:\test\" "-env:OOO_CWD=2C:\\Users\\username"

This command line is later processed in osl_createCommandArgs_Impl using CommandLineToArgvW, to split it to individual arguments. But the latter WinAPI function processes the sequence \" (backslash+doublequote) specially, i.e., in this case it treats this as escaped doublequote, inserting the unescaped doublequote into the resulting argument, instead of treating the doublequote as limiting the argument. So the part

> "c:\test\" "-env:OOO_CWD=2C:\\Users\\username"

is converted into one resulting argument

> c:\test" -env:OOO_CWD=2C:\\Users\\username

instead of expected two arguments:

> c:\test\
> -env:OOO_CWD=2C:\\Users\\username

which causes the error trying to write to a non-existing directory with a doublequote in the middle.

The described behavior is discussed in https://docs.microsoft.com/en-us/windows/desktop/api/shellapi/nf-shellapi-commandlinetoargvw.

Tested with Version: 6.1.2.1 (x64)
Build ID: 65905a128db06ba48db947242809d14d3f9a93fe
CPU threads: 12; OS: Windows 10.0; UI render: default; 
Locale: ru-RU (ru_RU); Calc: group threaded

and with LibreOffice 3.4.0 
OOO340m1 (Build:11)
Comment 1 Mike Kaganski 2018-10-01 18:36:31 UTC
https://gerrit.libreoffice.org/61214
Comment 2 Commit Notification 2018-10-01 20:50:30 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=f4103a42d58535e21c48ff94ab000ab0305c62e3

tdf#120249: escape trailing backslash in argument passed to soffice.bin

It will be available in 6.2.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 3 Commit Notification 2018-10-04 09:07:09 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "libreoffice-6-1":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=9bb9be742d74d412d27be3db4ce5ac5e9508cb5b&h=libreoffice-6-1

tdf#120249: escape trailing backslash in argument passed to soffice.bin

It will be available in 6.1.3.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 4 Commit Notification 2018-10-22 08:23:58 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=0b92d04ab61b4d39d714df6210d6f6bf8fdec5bf

tdf#120249: fix escaping to handle quotes and multiple trailing backslshes

It will be available in 6.2.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 5 MalcolmReynolds 2020-04-17 10:49:03 UTC Comment hidden (spam)
Comment 6 MalcolmReynolds 2020-04-23 08:39:26 UTC Comment hidden (obsolete, spam)