Bug 156967 - CALC: Basic: CSV import macro crashes Calc 7.6.0.3 (worked fine in 7.5)
Summary: CALC: Basic: CSV import macro crashes Calc 7.6.0.3 (worked fine in 7.5)
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
7.6.0.3 release
Hardware: x86-64 (AMD64) All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:24.2.0 target:7.6.2 target:7.6.1
Keywords: bibisected, bisected, regression
: 157045 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-08-28 12:58 UTC by BartS
Modified: 2023-09-06 12:35 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
Example CSV-file used (personal details edited) (823 bytes, application/vnd.ms-excel)
2023-08-28 12:58 UTC, BartS
Details
Use Case for reproducing bug (26.36 KB, application/vnd.oasis.opendocument.spreadsheet)
2023-08-29 07:02 UTC, BartS
Details

Note You need to log in before you can comment on or make changes to this bug.
Description BartS 2023-08-28 12:58:29 UTC
Created attachment 189199 [details]
Example CSV-file used (personal details edited)

I migrated from 7.5 to 7.6.0.3 this weekend on my Windows 10 laptop (details below). Running into trouble with a few of my macro's in Calc. I use them to process CSV-files which I download from my bank. The macro moves and opens the file and processes the content. They worked flawless in LO 7.5.

In version 7.6, those macro's consistently crash early in the process. I have narrowed it down to 'roughly somewhere in the code below'.

The error I get is the following:

BASIC runtime error.
An exception occurred
Type: com.sun.star.uno.RuntimeException
Message: [mscx_uno bridge error] UNO type of C++ exception unknown: "std.system_error", RTTI-name = ".?AVsystem_error@std@@"!.

Example CSV-file attached. Please have mercy on me, this is my first ever bug report...

```

Sub ImportFromMyBank()
	
	'Here is some initial code

	'Somewhere in the section below the macro and Calc crash.

	'Move file to Archive Directory
'DirDownloads and 'DirArchiveMyBank are named fields containing directory names
	FromPath = ThisComponent.NamedRanges.getByName("DirDownloads").getReferredCells.String
	ToPath = ThisComponent.NamedRanges.getByName("DirArchiveMyBank").getReferredCells.String
	ImportFileName = Dir(FromPath & "CSV_?_*.csv")
	ImportFileFullName = FromPath & ImportFileName
	
	If FileExists(ImportFileFullName) Then
		NewFullFileName = ToPath + ImportFileName
	Else
		MsgBox ("MyBank file does not exist.", MB_OK + MB_ICONINFORMATION, "GnuCash Converter")
		Exit Sub
	End If

	FileCopy ImportFileFullName, NewFullFileName
	Kill ImportFileFullName
   
	'Open requested xMyBank file and copy data
	path = ConvertToURL(NewFullFileName)

	opt(0).Name = "Hidden"
	opt(0).Value = True
	opt(1).Name = "FilterName"
	opt(1).Value = "Text - txt - csv (StarCalc)"
	opt(2).Name = "FilterOptions"
	opt(2).Value = "44,34,0,0,1/2/2/2/3/2/4/1/5/4/6/4/7/1/8/1/9/2/10/2/11/2/12/2/13/2/14/2/15/2/16/2/17/2/18/2/19/2/20/2/21/2/22/2/23/2/24/2/25/2/26/2,1,false,false,false,false,false"

	cell = ThisComponent.Sheets.getByName("Data").getCellRangeByName("A1") 'The "Data" worksheet exists, it is created in the Initial Code
	target = next_cell(cell)
	
	csv = StarDesktop.loadComponentFromURL(path, "_blank", 0, opt())
	sheet = csv.Sheets.getByIndex(0)
	cell = sheet.getCellRangeByName("A1")
	cursor = sheet.createCursorByRange(cell)
	cursor.collapseToCurrentRegion()
	ra = cursor.RangeAddress

	data = sheet.getCellRangeByPosition(ra.StartColumn, ra.StartRow, ra.EndColumn, ra.EndRow).DataArray
	copy_to(target, data)
	csv.close(True)

	'Here follows the rest of the macro processing the file

End Sub

	'----------- GENERIC FUNCTIONS -------------------

Function copy_to(cell, data)
	ra = cell.RangeAddress
	s = cell.SpreadSheet
	cols = ra.EndColumn + UBound(data(0))
	rows = ra.EndRow + Ubound(data)
	range = s.getCellRangeByPosition(ra.StartColumn, ra.StartRow, cols, rows)
	range.DataArray = data
	
End Function

Function next_cell(cell)

	cursor = cell.SpreadSheet.createCursorByRange(cell)
	cursor.gotoEnd()
	row = cursor.RangeAddress.EndRow
	next_cell = cell.SpreadSheet.getCellByPosition(0, row + 1)

End Function

```


-----
Version: 7.6.0.3 (X86_64) / LibreOffice Community
Build ID: 69edd8b8ebc41d00b4de3915dc82f8f0fc3b6265
CPU threads: 12; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL: win
Locale: nl-NL (nl_NL); UI: en-US
Calc: threaded
Comment 1 raal 2023-08-28 18:16:49 UTC
Hello, can you prepare a test case for easy reproduction? When I run your code, i got error.
Thank you
Comment 2 BartS 2023-08-29 07:02:52 UTC
Created attachment 189222 [details]
Use Case for reproducing bug

Please find enclosed a working usecase reproducing the bug. It should be used with the CSV-file provided earlier. Instructions are on the Dashboard worksheet in the spreadsheet.
Comment 3 raal 2023-08-29 18:35:56 UTC
This seems to have begun at the below commit in bibisect repository/OS linux-64-7.6.
Adding Cc: to Noel Grandin ; Could you possibly take a look at this one?
Thanks
 310675fe06d19ee48ca62bd486fe63c9ec8eed93 is the first bad commit
commit 310675fe06d19ee48ca62bd486fe63c9ec8eed93
Author: Jenkins Build User <tdf@pollux.tdf>
Date:   Tue Jan 31 07:07:27 2023 +0100

    source ba4191ff0de05334ba32b53a09ad992710f03f9d

146368: osl::Mutex->std::mutex in ImplEventAttacherManager | https://gerrit.libreoffice.org/c/core/+/146368
Comment 4 mhonline 2023-08-31 10:10:59 UTC
just an idea: you may look into the header of your CSV, the label
"Naam initi�rende partij" contains an unrecognizable character-code

mh
Comment 5 BartS 2023-08-31 10:17:35 UTC
(In reply to mhonline from comment #4)
> just an idea: you may look into the header of your CSV, the label
> "Naam initi�rende partij" contains an unrecognizable character-code
> 
> mh

Thanks, I will. However, I think that it cannot be the cause of this crash. I used the spreadsheet for almost a year with previous versions of LO. That label has always been there in the source CSV and it never caused a problem before.
Comment 6 Commit Notification 2023-08-31 13:21:23 UTC
Noel Grandin committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/b9d9f9ee71464425a52c5798503840b106b210bc

tdf#156967 cal basic, CSV import macro crashes

It will be available in 24.2.0.

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

Affected users are encouraged to test the fix and report feedback.
Comment 7 BartS 2023-08-31 14:03:40 UTC
(In reply to Commit Notification from comment #6)

> Affected users are encouraged to test the fix and report feedback.

Will do and report back.
Comment 8 Commit Notification 2023-09-01 11:28:57 UTC
Noel Grandin committed a patch related to this issue.
It has been pushed to "libreoffice-7-6":

https://git.libreoffice.org/core/commit/b04120235e25854734d5608902eeffd563e2c28f

tdf#156967 cal basic, CSV import macro crashes

It will be available in 7.6.2.

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

Affected users are encouraged to test the fix and report feedback.
Comment 9 Justin L 2023-09-01 13:30:13 UTC
*** Bug 157045 has been marked as a duplicate of this bug. ***
Comment 10 BartS 2023-09-04 12:04:12 UTC
(In reply to Commit Notification from comment #8)
> 
> Affected users are encouraged to test the fix and report feedback.

Tested LibreOfficeDev 7.6.2.0.0 build 2023_09_04_05.38.23 this morning, and can confirm that the bug is gone.
Comment 11 Commit Notification 2023-09-06 12:35:18 UTC
Noel Grandin committed a patch related to this issue.
It has been pushed to "libreoffice-7-6-1":

https://git.libreoffice.org/core/commit/280380751563c9bd654236f04cedfb855f0903f7

tdf#156967 cal basic, CSV import macro crashes

It will be available in 7.6.1.

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

Affected users are encouraged to test the fix and report feedback.