bugGNU Octave - Bugs: bug #64366, [Octave Packages] (io) : COM...

 
 

bug #64366: [Octave Packages] (io) : COM interface saves to current folder when asked to save to unwritable location

Submitter:  None
Submitted:  Thu 29 Jun 2023 01:11:50 AM UTC
   
 
Category:  Octave Forge Package Severity:  3 - Normal
Priority:  1 - Later Item Group:  Incorrect Result
Status:  Postponed Assigned to:  philipnienhuis
Originator Name:  Tom Cheng Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * other
Operating System:  * Microsoft Windows Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 14 Jul 2023 06:22:42 PM UTC, comment #17: 

BTW, adapting title - it's not just xlswrite.m but also xlsclose.m and associated private functions that invoke COM/ActiveX

Philip Nienhuis <philipnienhuis>
Group Member
Fri 14 Jul 2023 06:19:48 PM UTC, comment #16: 

Some debugging confirms that Excel (ActiveX) silently saves to the current directory if asked to save to an unwritable location. I'm quite sure this used to work fine in older MS-Office releases.
Perhaps this bug can be circumvented but at the cost of quite a bit of potentially kludgy code only meant for the COM interface.
I'm not going to spend time on this essentially upstream bug. Maybe someone will turn up who wants and can fix this.

Setting status to "postponed" and lowering priority

Philip Nienhuis <philipnienhuis>
Group Member
Thu 13 Jul 2023 09:29:37 PM UTC, comment #15: 

Right, I can reproduce the OP's exact steps but only using the COM interface (= ActiveX & Excel behind the scenes). It may be an upstream bug in MS-Office itself then.

At the OP: what spreadsheet I/O interface did you use?
If you don't know, please repeat with this command:
xlswrite('c:\test1.xlsx', a, '', '', 1)
and copy output verbatim here.

As noted in other comments, saving a spreadsheet file to the root of the system drive shouldn't be possible at all. The bug is that Octave emits no error but happily writes to the current directory instead.
I'll have a deeper look.

At the OP: what spreadsheet I/O interface did you use?
If you don't know, please repeat with this command:
xlswrite('c:\test1.xlsx', a, '', '', 1)
and copy output verbatim here.

Status -> confirmed
Item group: incorrect result
Release: other (because OF package, not core Octave)
Operating system: Windows (as Dmitri showed in comment #7 that in Linux the behavior is in principle OK)

Philip Nienhuis <philipnienhuis>
Group Member
Thu 13 Jul 2023 08:48:18 PM UTC, comment #14: 

Referring further to comment #10 and comment #7:

I've checked and improved the file closing code parts for the OCT interface here:
https://sourceforge.net/p/octave/io/ci/c40fa6f6ff46b6e07397a7bc5f81f8302af472c1/

The reason that Octave would end up in the scratch dir rather than in PWD in case of errors turned out to be an unnecessary 'warning (err.stack)' statement, probably left over from debugging.

OK, next step is trying to reproduce the OP's error ...
Was anyone else able to do reproduce it?

Philip Nienhuis <philipnienhuis>
Group Member
Sat 01 Jul 2023 01:27:04 PM UTC, comment #13: 

Referring to comment #10 and comment #7:

> Yes PWD should be restored in case of write errors, and that's another bug. In fact I saw exactly the same as you and IIRC I had fixed that a long time ago but apparently it creeped back in :-(

The code to restore PWD is in place and outside a try-catch block that encloses potentially failing file processing; so AFAICS it should still be working fine.
I'll dive into it later on; s/th for a separate bug report.

Philip Nienhuis <philipnienhuis>
Group Member
Fri 30 Jun 2023 09:33:08 PM UTC, comment #12: 


> Could this bug depends on interface being used? If Windows has Excel installed, does xlswrite default to activeX?


Yes, and yes it should - provided the OF windows package has also been loaded.
Actually the I/O interface preference order, that apart from available external & "activated" support SW also depends on file type, is defined in xlsopen.m in an if-elseif block starting at L.334.
For .xlsx it is COM (ActiveX) / Apache POI / UNO (LibreOffice) / OCT (native Octave).

Philip Nienhuis <philipnienhuis>
Group Member
Fri 30 Jun 2023 08:50:29 PM UTC, comment #11: 

Could this bug depends on interface being used? If Windows has Excel installed, does xlswrite default to activeX?

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Fri 30 Jun 2023 08:45:27 PM UTC, comment #10: 

@Dmitri:
Yes PWD should be restored in case of write errors, and that's another bug. In fact I saw exactly the same as you and IIRC I had fixed that a long time ago but apparently it creeped back in :-(

Indeed these days the root of the system drive (usually C:\) isn't writable. It still used to be writable in Windows XP but that's way way back.

Should that VM traceback and error mix-up be reported?

Still I cannot reproduce the original error.

Philip Nienhuis <philipnienhuis>
Group Member
Fri 30 Jun 2023 07:32:00 PM UTC, comment #9: 

This has to be a different bug report, it has nothing to do with the original.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Fri 30 Jun 2023 07:26:12 PM UTC, comment #8: 

Oh, so I see that my VM was enabled when running the test.

Without VM, I don't see a problem writing to "/tmp/foo.xlsx".

Changing bug header to match.

Arun Giridhar <arungiridhar>
Group Member
Fri 30 Jun 2023 07:18:41 PM UTC, comment #7: 

I think C:\ is not writable by normal user. If I try to write in write protected directory (in linux) I get:


octave:9>  a = 10; xlswrite ("/foo2.xlsx", a)
mv: cannot move './foo2.zip' to '/foo2.xlsx': Permission denied
mv: cannot move 'foo2.zip' to '/foo2.xlsx': Permission denied
xlsclose: could not zip files in /tmp/oct-YWAjnl to /foo2.xlsx
warning: xlsclose: Moving file "/tmp/oct-YWAjnl/foo2.zip" to "/foo2.xlsx" failed with message: ""
warning: called from
    __OCT_spsh_close__ at line 76 column 9
    xlsclose at line 139 column 13
    xlswrite at line 242 column 11

warning: xlsclose: file /foo2.xlsx could not be saved.
Read-only? unsupported file format? in use elsewhere?
(File pointer preserved.
 Try saving again later, or with different file name, or as different file type.)
error: warning: STATE structure must have fields 'identifier' and 'state'
error: called from
    __OCT_spsh_close__ at line 77 column 9
    xlsclose at line 139 column 13
    xlswrite at line 242 column 11
octave:10> ls
'[Content_Types].xml'   docProps   foo2.zip   _rels   xl
octave:11> pwd
ans = /tmp/oct-YWAjnl


The fact that my PWD now is different is also some kind of bug
in IO package.

Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Fri 30 Jun 2023 07:06:12 PM UTC, comment #6: 

That does look like a VM issue:

Without VM:

octave:1> pkg load io
octave:2> a = 10; xlswrite ("/tmp/foo.xlsx", a)
ans = 1
octave:3> stat("/tmp/foo.xlsx")
ans =

  scalar structure containing the fields:

    dev = 66307
    ino = 933172
    mode = 33188
    modestr = -rw-r--r--
    nlink = 1
    uid = 1001
    gid = 1001
    rdev = 0
    size = 6874
    atime = 1.6882e+09
    mtime = 1.6882e+09
    ctime = 1.6882e+09
    blksize = 4096
    blocks = 16

octave:4>


With VM:


octave:1> __enable_vm_eval__ (1)
octave:2> pkg load io
octave:3> a = 10; xlswrite ("/tmp/foo2.xlsx", a)
error: concatenation operator not implemented for 'matrix' by 'scalar struct' operations
error: called from
    __OCT_oct2xlsx__
    __OCT_oct2spsh__ at line 90 column 9
    oct2xls
    xlswrite
octave:4>


Dmitri.
--

Dmitri A. Sergatskov <dasergatskov>
Fri 30 Jun 2023 06:24:56 PM UTC, comment #5: 

Hmm I'm leaving for a week and just had time for a small test.
For me it works as designed with Octave-9.0.0 and io-2.6.5 which equals io-2.6.4. apart from latest patches for JSON file handling.

@Arun:
Exactly what error / bug did you confirm? I'd you hit & confirmed quite another issue.
Because what I find bizarre is that one traceback line in the third verbatim block in your comment #3 mentions 'L.90 in __OCT_oct2spsh__.m ' but AFAICS that function only has 83 lines ...
Did you by any chance test with Petter's VM patches? (sorry for the unintended implied whataboutism ... :-) )

The error messages you get show no line number for the actual originating function (hmmm...) but looking at them I think they might come from e.g., L.84 in

private/__OCT_oct2xlsx__.m:
+verbatim+
.xls.sheets.shId = [xls.sheets.shId (max (xls.sheets.shId(wid)) + 1) ];
-verbatim-
where simply some numeric index is added to an array of such indices in a struct field.
Similar constructs are in L.177, L.187. Elsewhere strings are concatenated.


Anyway, that is not the bug the OP reported and that I cannot reproduce.

Philip Nienhuis <philipnienhuis>
Group Member
Thu 29 Jun 2023 07:12:00 PM UTC, comment #4: 

Add to say: My tests were with IO 2.6.4 on Octave 9 dev (984bca088143).

Arun Giridhar <arungiridhar>
Group Member
Thu 29 Jun 2023 07:07:40 PM UTC, comment #3: 

This is really odd behavior. Confirming.

On Linux, I get:


octave:1> pkg load io

octave:2> a = 10; xlswrite ("foo.xlsx", a)
ans = 1

octave:3> a = 10; xlswrite ("/tmp/foo.xlsx", a)
error: concatenation operator not implemented for 'matrix' by 'scalar struct' operations
error: called from
    __OCT_oct2xlsx__
    __OCT_oct2spsh__ at line 79 column 16
    oct2xls
    xlswrite


The bizarre part is that I tried to cd to /tmp and then creating a foo.xlsx, but it gave me an error, both when changing directories inside Octave and outside it in the shell prompt!


octave:3> cd /tmp
octave:4> a = 10; xlswrite ("foo.xlsx", a)
error: concatenation operator not implemented for 'matrix' by 'scalar struct' operations
error: called from
    __OCT_oct2xlsx__
    __OCT_oct2spsh__ at line 79 column 16
    oct2xls
    xlswrite



$ cd /tmp      ## in Bash

$ octave -q
octave:1> pkg load io
octave:2> a = 10; xlswrite ("foo.xlsx", a)
error: concatenation operator not implemented for 'matrix' by 'scalar struct' operations
error: called from
    __OCT_oct2xlsx__
    __OCT_oct2spsh__ at line 90 column 9
    oct2xls
    xlswrite


Arun Giridhar <arungiridhar>
Group Member
Thu 29 Jun 2023 01:48:52 AM UTC, comment #2: 

comment #1:

> Use double backslash instead of single. Escape sequence interference.


Hi Rich, I tried the double backslash as suggested but still got the same results. The file was saved to current directory only.

Anonymous
Thu 29 Jun 2023 01:21:43 AM UTC, comment #1: 

Use double backslash instead of single. Escape sequence interference.

Anonymous
Thu 29 Jun 2023 01:11:50 AM UTC, original submission:  

I tried to use xlswrite to save data to an Excel file and found that the file will be saved to current directory only.  If you save file to other directory, it still saves the file to current directly.  This will cause problem when you want to save data in multiple spreadsheets in different directory.  The saved file only shown on the current directoy and only the last spreadsheets existed.  Below is my testing code.
------------------------------

>> pwd

ans = C:\TomCheng\Matlab\IMGtool

>> a=0;
>> xlswrite('c:\test1.xlsx',a)

ans = 1

>>

-------------------------------
The file test1.xlsx was created on directory C:\TomCheng\Matlab\IMGtool

Below is my system configuration
OS: Windows 11
Octave: 8.2.0
IO package: 2.6.4

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by philipnienhuis
  • -email is unavailable- added by dasergatskov (Posted a comment)
  • -email is unavailable- added by arungiridhar (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only project members can vote.

     

    Follow 20 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-07-14 philipnienhuis Summary[Octave Packages] (io) : xlswrite doesn't error when asked to save to unwritable location but saves to current folder [Octave Packages] (io) : COM interface saves to current folder when asked to save to unwritable location
    2023-07-14 philipnienhuis Priority5 - Normal 1 - Later
        StatusConfirmed Postponed
    2023-07-13 philipnienhuis Assigned toNone philipnienhuis
    2023-07-13 philipnienhuis Item GroupUnexpected Error or Warning Incorrect Result
        StatusIn Progress Confirmed
        Release8.2.0 other
        Operating SystemAny Microsoft Windows
        Summary[Octave Packages] (io) : xlswrite errors in certain cases [Octave Packages] (io) : xlswrite doesn't error when asked to save to unwritable location but saves to current folder
    2023-06-30 arungiridhar Summary[Octave Packages] (io) / VM : xlswrite errors in certain cases [Octave Packages] (io) : xlswrite errors in certain cases
    2023-06-30 philipnienhuis Carbon-Copy- Added philipnienhuis
    2023-06-30 philipnienhuis Carbon-CopyRemoved prnienhuis -
    2023-06-30 arungiridhar StatusConfirmed In Progress
        Summary[Octave Packages] (io) xlswrite can only save file to a specific directory [Octave Packages] (io) / VM : xlswrite errors in certain cases
    2023-06-29 arungiridhar Carbon-Copy- Added prnienhuis
    2023-06-29 arungiridhar Summary[Octave Packages] (io) xlswrite can only save file to current directory [Octave Packages] (io) xlswrite can only save file to a specific directory
    2023-06-29 arungiridhar Item GroupOther Unexpected Error or Warning
        StatusNone Confirmed
        Operating SystemMicrosoft Windows Any
        Summaryxlswrite can only save file to current directory [Octave Packages] (io) xlswrite can only save file to current directory

    Back to the top

    Powered by Savane 3.12