Bug 147611 - UI: Assert when running a macro (regression in 7.3)
Summary: UI: Assert when running a macro (regression in 7.3)
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
7.3.0.3 release
Hardware: All All
: medium normal
Assignee: Mike Kaganski
URL:
Whiteboard: target:7.4.0 target:7.3.2
Keywords:
Depends on:
Blocks:
 
Reported: 2022-02-23 12:11 UTC by simao.afonso
Modified: 2022-02-24 10:31 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
testcase (300.00 KB, application/vnd.ms-excel)
2022-02-23 13:05 UTC, simao.afonso
Details
A problematic document (48.50 KB, application/vnd.ms-excel)
2022-02-23 13:06 UTC, Mike Kaganski
Details

Note You need to log in before you can comment on or make changes to this bug.
Description simao.afonso 2022-02-23 12:11:29 UTC
Description:
I have a file with a specific macro that always crashes Calc with the following assertion:

/usr/include/c++/11.2.0/bits/stl_vector.h:1045: std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = ScSortKeyState; _Alloc = std::allocator<ScSortKeyState>; std::vector<_Tp, _Alloc>::reference = ScSortKeyState&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]: Assertion '__n < this->size()' failed.

This is a regression, downgrading to "LibreOffice 7.2.4.1 20(Build:1)" fixes the problem.

The macro code is the following (not sure if it helps). I don't know where exactly it crashes:

```
Public Sub GenerateWeeklyReport()
    Row_Min = 3                '"Tasks" area starts at Row 3
    Row_Max = 62               '"Tasks" area ends at Row 62
    Col_TaskNr = 1             '"Task Nr"       at Column  1
    Col_Task = 2               '"Task Descript" at Column  2
    Col_Track = 9              '"Track"         at Column  9
    Col_TotEff = 20            '"TotEff"        at Column 20
    Col_WkyEff = 21            '"WkyEff"        at Column 21
    Col_WkyEffHM = 22          '"WkyEffHM"      at Column 22
    Col_DoingIt = 23           '"DoingIt"       at Column 23
    Col_TotPastEff = 24        '"TotPastEff"    at Column 24
    Col_WkyPastEff = 25        '"WkyPastEff"    at Column 25
    Col_StartedAt = 26         '"Started At"    at Column 26

    Set WrkstTasks = Worksheets("tasks")
    Set WrkstLog = Worksheets("report")
    
    'clear all
    WrkstLog.Range(Cells(1, 1), Cells(Row_Max, 3)).ClearContents
    'reset to not bold
    WrkstLog.Range(Cells(1, 1), Cells(Row_Max, 3)).Select
    Selection.Font.Bold = False
    
    r = 1
    TrkAEff = 0#
    TrkBEff = 0#
    spentMw = 0#
    For i = Row_Min To Row_Max
        If WrkstTasks.Cells(i, Col_WkyEff) <> "" Then
            If WrkstTasks.Cells(i, Col_WkyEff) > 0 Then
                taskMw = 0.001 * Int(1000 * (0.2 * WrkstTasks.Cells(i, Col_WkyEff) + 0.0005))
                TaskDes = WrkstTasks.Cells(i, Col_Task)
                taskTrk = Left(WrkstTasks.Cells(i, Col_Track), 1)
                WrkstLog.Cells(r, 1) = taskTrk
                WrkstLog.Cells(r, 2) = taskMw
                WrkstLog.Cells(r, 3) = TaskDes
                If taskTrk = "A" Then
                    TrkAEff = TrkAEff + taskMw
                End If
                If taskTrk = "B" Then
                    TrkBEff = TrkBEff + taskMw
                End If
                spentMw = spentMw + taskMw
                r = r + 1
            End If
        End If
    Next i
    ' print total
    r2 = r
    WrkstLog.Cells(r2, 2) = spentMw
    WrkstLog.Cells(r2, 3) = "Total"
    ' print availability
    r2 = r2 + 1
    If spentMw <> 0 Then
        WrkstLog.Cells(r2, 2) = 100 * TrkAEff / spentMw
    Else
        WrkstLog.Cells(r2, 2) = 0
    End If
    WrkstLog.Cells(r2, 3) = "Track A load so far (in percentage)"
    
    r2 = r2 + 1
    
    If spentMw <> 0 Then
        WrkstLog.Cells(r2, 2) = 100 * TrkBEff / spentMw
    Else
        WrkstLog.Cells(r2, 2) = 0
    End If
    WrkstLog.Cells(r2, 3) = "Track B load so far (in percentage)"
    
    ' Bold Total and Availability rows
    WrkstLog.Range(Cells(r, 1), Cells(r2, 3)).Select
    Selection.Font.Bold = True
    

    '--- re-sort by time-spent in the task ---
    If r <> 1 Then
        Calculate
        'ActiveSheet.Unprotect
        Range(Cells(1, 1), Cells(r - 1, 3)).Select
        Selection.Sort Key1:=Range("B1"), Header:=False, Order1:=xlDescending, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
             DataOption1:=xlSortNormal
        'ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
        WrkstLog.Cells(1, 3).Select

        'Response = MsgBox("Copying report to clipboard. OK to proceed. Cancel will not copy.", vbOKCancel, "Copying report to clipboard")
        'If Response = vbOK Then
        If WrkstLog.Cells(7, 14) = True Then
            WrkstLog.Activate
            WrkstLog.Range(Cells(1, 2), Cells(r - 1, 3)).Select
            Selection.Copy
            WrkstLog.Cells(1, 3).Select
        End If
    End If
End Sub
```

Steps to Reproduce:
1. Click the form button that runs the macro

Actual Results:
1. Program crashes with assertion

Expected Results:
1. Execute the macro as before.


Reproducible: Always


User Profile Reset: Yes



Additional Info:
Crashing Version:

Version: 7.3.0.3 / LibreOffice Community
Build ID: 30(Build:3)
CPU threads: 4; OS: Linux 5.16; UI render: default; VCL: gtk3
Locale: pt-PT (en_GB.UTF-8); UI: en-GB
7.3.0-5
Calc: threaded

Working Version:
Version: 7.2.4.1 / LibreOffice Community
Build ID: 20(Build:1)
CPU threads: 4; OS: Linux 5.16; UI render: default; VCL: gtk3
Locale: pt-PT (en_GB.UTF-8); UI: en-GB
7.2.4-3
Calc: threaded

I'm using Arch Linux.
Comment 1 Xisco Faulí 2022-02-23 12:22:19 UTC
Thank you for reporting the bug. Please attach a sample document, as this makes it easier for us to verify the bug. 
I have set the bug's status to 'NEEDINFO'. Please change it back to 'UNCONFIRMED' once the requested document is provided.
(Please note that the attachment will be public, remove any sensitive information before attaching it. 
See https://wiki.documentfoundation.org/QA/FAQ#How_can_I_eliminate_confidential_data_from_a_sample_document.3F for help on how to do so.)
Comment 2 simao.afonso 2022-02-23 13:05:06 UTC
Created attachment 178482 [details]
testcase

The bug can be triggered by clicking the "Generate Report" button, on the "tasks" tab.

The current sheet state is the intended output.
Comment 3 Mike Kaganski 2022-02-23 13:06:18 UTC
Created attachment 178483 [details]
A problematic document

Repro with current master.
Comment 4 simao.afonso 2022-02-23 13:14:50 UTC
@Mike Kaganski Thanks for that, it's even more minimal.
Comment 5 Xisco Faulí 2022-02-23 13:16:55 UTC
@Mike, your attachment doesn't crash for me in

Version: 7.4.0.0.alpha0+ / LibreOffice Community
Build ID: 0723b41bed9bb4ad50d2993744a60177966d1a21
CPU threads: 8; OS: Linux 5.10; UI render: default; VCL: x11
Locale: es-ES (es_ES.UTF-8); UI: en-US
Calc: threaded

Win only ?
Comment 6 Xisco Faulí 2022-02-23 13:17:54 UTC
OTOH, the original report happens with gtk3
Comment 7 Mike Kaganski 2022-02-23 13:27:03 UTC
(In reply to Xisco Faulí from comment #5)
> @Mike, your attachment doesn't crash for me in
> 
> Version: 7.4.0.0.alpha0+ / LibreOffice Community

Do you use debug build? Assertions only fire there.
Comment 8 Mike Kaganski 2022-02-23 13:30:41 UTC
(In reply to simao.afonso from comment #0)
> /usr/include/c++/11.2.0/bits/stl_vector.h:1045: std::vector<_Tp,
> _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp,
> _Alloc>::size_type) [with _Tp = ScSortKeyState; _Alloc =
> std::allocator<ScSortKeyState>; std::vector<_Tp, _Alloc>::reference =
> ScSortKeyState&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]:
> Assertion '__n < this->size()' failed.
> 
> ...
> 
> Crashing Version:
> 
> Version: 7.3.0.3 / LibreOffice Community
> Build ID: 30(Build:3)
> CPU threads: 4; OS: Linux 5.16; UI render: default; VCL: gtk3
> Locale: pt-PT (en_GB.UTF-8); UI: en-GB
> 7.3.0-5
> Calc: threaded
> 
> ...
> 
> I'm using Arch Linux.

I suspect that Arch could publish debug version by mistake, which would mean that regression is not granted - it might be that it is just invisible in release versions that were used before.
Comment 9 Xisco Faulí 2022-02-23 14:01:29 UTC
Moving to NEW based on comment 3
Comment 10 simao.afonso 2022-02-23 15:27:50 UTC
@Xisco Faulí(In reply to Mike Kaganski from comment #8)
> I suspect that Arch could publish debug version by mistake, which would mean
> that regression is not granted - it might be that it is just invisible in
> release versions that were used before.

https://github.com/archlinux/svntogit-packages/blob/packages/libreoffice-fresh/trunk/PKGBUILD#L169

From what I can tell, this hasn't changed in the versions I'm using. The only major change was enabling LTO.

Maybe the build process changed?
Comment 11 Mike Kaganski 2022-02-23 15:29:25 UTC
Definitely was not a regression in 7.3 (but it was in 3.6 after tdf#45747) - it seems that no one ever run Range.Sort VBA method in a debug build. It's great that sometimes maintainers do mistakes, that allow to discover problems accidentally :)

https://gerrit.libreoffice.org/c/core/+/130441
Comment 12 Mike Kaganski 2022-02-23 15:32:52 UTC
(In reply to simao.afonso from comment #10)
> https://github.com/archlinux/svntogit-packages/blob/packages/libreoffice-
> fresh/trunk/PKGBUILD#L169

Note that --enable-release-build is orthogonal to debug builds (i.e., use of --enable-dbgutil or --enable-debug, which may be used together with the former - but they don't appear in the script, either).

Maybe we really have changed the defaults wrt the debug arguments, as you suspect?
Comment 13 Commit Notification 2022-02-23 21:43:13 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/7234576d4e3a6b384168a84165b59ee7751cda62

tdf#147611: fix indices

It will be available in 7.4.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 14 Commit Notification 2022-02-24 10:31:58 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "libreoffice-7-3":

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

tdf#147611: fix indices

It will be available in 7.3.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.