Bug 372254 - Crash when importing CSV file
Summary: Crash when importing CSV file
Status: RESOLVED FIXED
Alias: None
Product: kmymoney
Classification: Applications
Component: importer (show other bugs)
Version: git (master)
Platform: Kubuntu Linux
: NOR crash
Target Milestone: ---
Assignee: KMyMoney Devel Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-09 11:24 UTC by allan
Modified: 2018-03-28 08:00 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 5.0.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description allan 2016-11-09 11:24:47 UTC
The crash of KMM seems to happen every time, at least with one particular account.  I get Segmentation fault (core dumped)
but with no other detail.
Comment 1 allan 2016-11-09 22:59:11 UTC
(In reply to allan from comment #0)
> The crash of KMM seems to happen every time, at least with one particular
> account.  I get Segmentation fault (core dumped)
> but with no other detail.

The Segmentation fault (core dumped) is not related to this problem, but seems to occur whenever KMM is closed.

The main problem here was triggered by resource file content for this account, which I have now removed.  What actually caused the crash looks to be an out of bounds index, but unfortunately I'm not familiar with the logic here.
Comment 2 allan 2016-11-10 13:25:17 UTC
I think I can see what has happened.
I have created a profile for one of my banks, but I have more than one account there.  The checking account has one column for the Amount, whereas the savings account has columns for both credits and debits.  The latter therefore has more columns, and the column numbers from this account were saved in the resource file.

If now a checking account is loaded, the saved column details will include more columns than in the checking file.  Therefore, the result is that an attempt is made to access a nonexistent column, and an out-of-bounds index is generated.

This happens circa line 576-578 in bankingwizardpage.cpp -

if (!memo.isEmpty())
        memo.append(QChar(QLatin1Char('\n')));
      memo.append(m_columnList[m_wiz->m_memoColList[i]]);

I have inserted

if (m_wiz->m_memoColList[i] < m_columnList.count())  // avoid out of bounds

before the last line to avoid it going out of bounds.

This avoids the problem, but an additional profile will be needed to cover the different formats.  Has anyone else a more elegant solution?
Comment 3 allan 2016-11-10 21:40:55 UTC
Totally unconnected, but I previously reported that I'd noticed the following -

"QObject::connect: No such signal
FormatsPage::statementReady(MyMoneyStatement&)
QObject::connect:  (sender name:   'FormatsPage')
QObject::connect:  (receiver name: 'csvimport')
KMyMoneyPlugin::KMMStatementInterface::import start
Updating account in MyMoneyStatementReader::startImport failed
Importing statement for ''
Importing statement for '' done
QObject::connect: No such signal
FormatsPage::statementReady(MyMoneyStatement&)
QObject::connect:  (sender name:   'FormatsPage')
QObject::connect:  (receiver name: 'csvimport')
KMyMoneyPlugin::KMMStatementInterface::import start"

A single line needed to be edited, which I've done in the code for this bug.
Do I need to raise a separate bug or add it to this one?

I can add the two fixes as an attachment here.
Comment 4 allan 2016-11-30 11:54:41 UTC
(In reply to allan from comment #1)
> (In reply to allan from comment #0)
> > The crash of KMM seems to happen every time, at least with one particular
> > account.  I get Segmentation fault (core dumped)
> > but with no other detail.
> 
> The Segmentation fault (core dumped) is not related to this problem, but
> seems to occur whenever KMM is closed.

In connection with this crash on exiting, which happens every time, I've just noticed a little more detail, which I had not noticed previously.

"QXcbConnection: XCB error: 3 (BadWindow), sequence: 19563, resource id: 35699775, major code: 40 (TranslateCoords), minor code: 0
Segmentation fault (core dumped) "

It means little to me, but most likely one of the devs will have a clue.
Comment 5 wojnilowicz 2016-12-31 11:51:06 UTC
Based on comment #2:
Different CSV files structures (amount input vs debit/credit input) require different importing profiles. It's not a bug if you import CSV file with wrong import profile.
Comment 6 allan 2016-12-31 22:41:25 UTC
(In reply to NSLW from comment #5)
> Based on comment #2:
> Different CSV files structures (amount input vs debit/credit input) require
> different importing profiles. It's not a bug if you import CSV file with
> wrong import profile.

That is obviously the case.  However, if it results in a crash, is that also not a bug?  I'm not happy to leave this so and am reopening the bug.
Comment 7 wojnilowicz 2017-01-22 15:20:50 UTC
Git commit 26f156543002b704d656b57764bcf3c87c2514c5 by Łukasz Wojniłowicz, on behalf of Allan Anderson.
Committed on 22/01/2017 at 14:39.
Pushed by wojnilowicz into branch 'master'.

Don't go out of bounds of m_columnList
FIXED-IN: 5.0
Signed-off-by: Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>

M  +2    -1    kmymoney/plugins/csvimport/bankingwizardpage.cpp
M  +2    -1    kmymoney/plugins/csvimport/investmentwizardpage.cpp

https://commits.kde.org/kmymoney/26f156543002b704d656b57764bcf3c87c2514c5