Bug 291730 - Entering number prefixed with zero is interpreted as octal
Summary: Entering number prefixed with zero is interpreted as octal
Status: RESOLVED FIXED
Alias: None
Product: kmymoney
Classification: Applications
Component: general (show other bugs)
Version: 4.6.1
Platform: Arch Linux Linux
: NOR crash
Target Milestone: ---
Assignee: KMyMoney Devel Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-17 03:28 UTC by David Chamberlain
Modified: 2012-01-18 18:45 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Patch that fixes this bug. (1.93 KB, patch)
2012-01-17 20:31 UTC, Cristian Oneț
Details
Updated patch to handle std::invalid_argument in unforeseen cases. (2.71 KB, patch)
2012-01-17 21:23 UTC, Cristian Oneț
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Chamberlain 2012-01-17 03:28:08 UTC
Version:           4.6.1 (using KDE 4.7.4) 
OS:                Linux

When creating a "Buy shares" transaction in an investment account, I happened to enter "0200" in the shares box.  (The zero was already there and the cursor wound up to the right of it, so I just added "200" thinking it shouldn't matter.)  After I finished the transaction, the number of shares shown in the ledger was 128 instead of 200.  If you enter an invalid octal number prefixed by zero (e.g. "09"), it will crash immediately. 

Reproducible: Always

Steps to Reproduce:
Open investment account.  Start new "Buy shares" transaction.  In the "Shares" box, enter "0200".  (Don't enter an invalid octal number or it will crash!!)

Actual Results:  
Number is interpreted as octal.

Expected Results:  
Number should be interpreted as decimal.  (And not crash if you enter "09"!)

OS: Linux (x86_64) release 3.1.9-2-ARCH
Compiler: gcc
Comment 1 Cristian Oneț 2012-01-17 05:59:33 UTC
I can't reproduce this. Entering 0200 leaves me with 200, 09 results in 9 and so on. Anyone else can reproduce this?
Comment 2 David Houlden 2012-01-17 09:47:49 UTC
Yes, I can reproduce it. When entering the quantity, leave the zero in the field, position the cursor after the zero and press 9. This results in an instant crash. This is the output from running under gdb.

Starting program: /usr/local/src/extras/kmymoney-git/build-debug/kmymoney/kmymoney 
[Thread debugging using libthread_db enabled]
kmymoney(23659)/kdecore (KPluginInfo) KPluginInfo::kcmServices: found  0  offers for  "Reconciliation report"
kmymoney(23659)/kdecore (KPluginInfo) KPluginInfo::kcmServices: found  0  offers for  "csvimport"
kmymoney(23659)/kdecore (KPluginInfo) KPluginInfo::kcmServices: found  1  offers for  "Print check"
kmymoney(23659)/kdecore (KPluginInfo) KPluginInfo::kcmServices: found  1  offers for  "iCalendar"
KMyMoney reconciliation report plugin loaded
KMyMoney csvimport plugin loaded
KMyMoney printcheck plugin loaded
kmymoney(23659)/kdecore (KConfigSkeleton) KCoreConfigSkeleton::writeConfig:
QFSFileEngine::open: No file name specified
KMyMoney iCalendar plugin loaded
[New Thread 0xb09a0b70 (LWP 23662)]
reading file
start parsing file
startDocument
reading accounts
reading transactions
reading securities
reading currencies
reading prices
reading reports
endDocument
terminate called after throwing an instance of 'std::invalid_argument'
  what():  mpq_set_str

Program received signal SIGABRT, Aborted.
0xb5bb32d7 in raise () from /lib/libc.so.6
(gdb) bt
#0  0xb5bb32d7 in raise () from /lib/libc.so.6
#1  0xb5bb4cee in abort () from /lib/libc.so.6
#2  0xb5dd8c05 in __gnu_cxx::__verbose_terminate_handler() () from /usr/lib/libstdc++.so.6
#3  0xb5dd6b25 in ?? () from /usr/lib/libstdc++.so.6
#4  0xb5dd6b62 in std::terminate() () from /usr/lib/libstdc++.so.6
#5  0xb5dd6d3b in __cxa_rethrow () from /usr/lib/libstdc++.so.6
#6  0xb6ab2e3d in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) ()
   from /usr/lib/qt/lib/libQtCore.so.4
#7  0xb63c4603 in QLineEdit::textChanged(QString const&) () from /usr/lib/qt/lib/libQtGui.so.4
#8  0xb63c4bad in QLineEdit::qt_metacall(QMetaObject::Call, int, void**) ()
   from /usr/lib/qt/lib/libQtGui.so.4
#9  0xb75c1cfa in KLineEdit::qt_metacall(QMetaObject::Call, int, void**) ()
   from /usr/lib/libkdeui.so.5
#10 0x081cccff in kMyMoneyLineEdit::qt_metacall (this=0x972cfc8, _c=QMetaObject::InvokeMetaMethod, 
    _id=27, _a=0xbfffdab8)
    at /usr/local/src/extras/kmymoney-git/build-debug/kmymoney/widgets/kmymoneylineedit.moc:71
#11 0xb6aa2b7a in QMetaObject::metacall(QObject*, QMetaObject::Call, int, void**) ()
   from /usr/lib/qt/lib/libQtCore.so.4
#12 0xb6ab29bd in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) ()
   from /usr/lib/qt/lib/libQtCore.so.4
#13 0xb665d663 in QLineControl::textChanged(QString const&) () from /usr/lib/qt/lib/libQtGui.so.4
#14 0xb63c9bcb in QLineControl::finishChange(int, bool, bool) () from /usr/lib/qt/lib/libQtGui.so.4
#15 0xb63cb313 in QLineControl::insert(QString const&) () from /usr/lib/qt/lib/libQtGui.so.4
#16 0xb63cc079 in QLineControl::processKeyEvent(QKeyEvent*) () from /usr/lib/qt/lib/libQtGui.so.4
#17 0xb63bfc45 in QLineEdit::keyPressEvent(QKeyEvent*) () from /usr/lib/qt/lib/libQtGui.so.4
#18 0xb75c3249 in KLineEdit::keyPressEvent(QKeyEvent*) () from /usr/lib/libkdeui.so.5
#19 0x081ccb73 in kMyMoneyLineEdit::keyPressEvent (this=0x972cfc8, k=0xbfffe474)
    at /usr/local/src/extras/kmymoney-git/kmymoney/kmymoney/widgets/kmymoneylineedit.cpp:168
#20 0xb5fba778 in QWidget::event(QEvent*) () from /usr/lib/qt/lib/libQtGui.so.4
#21 0xb63c2897 in QLineEdit::event(QEvent*) () from /usr/lib/qt/lib/libQtGui.so.4
#22 0xb75c04e8 in KLineEdit::event(QEvent*) () from /usr/lib/libkdeui.so.5
#23 0xb5f618c4 in QApplicationPrivate::notify_helper(QObject*, QEvent*) ()
   from /usr/lib/qt/lib/libQtGui.so.4
#24 0xb5f66e19 in QApplication::notify(QObject*, QEvent*) () from /usr/lib/qt/lib/libQtGui.so.4
#25 0xb74e126a in KApplication::notify(QObject*, QEvent*) () from /usr/lib/libkdeui.so.5
#26 0xb6a9c52b in QCoreApplication::notifyInternal(QObject*, QEvent*) ()
   from /usr/lib/qt/lib/libQtCore.so.4
#27 0xb5f5f98e in ?? () from /usr/lib/qt/lib/libQtGui.so.4
#28 0xb600e9bf in ?? () from /usr/lib/qt/lib/libQtGui.so.4
---Type <return> to continue, or q <return> to quit---
#29 0xb600edcf in ?? () from /usr/lib/qt/lib/libQtGui.so.4
#30 0xb5fe8ba2 in QApplication::x11ProcessEvent(_XEvent*) () from /usr/lib/qt/lib/libQtGui.so.4
#31 0xb6012ec2 in ?? () from /usr/lib/qt/lib/libQtGui.so.4
#32 0xb5238432 in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#33 0xb5238c10 in ?? () from /usr/lib/libglib-2.0.so.0
#34 0xb5238ec4 in g_main_context_iteration () from /usr/lib/libglib-2.0.so.0
#35 0xb6ac9bac in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ()
   from /usr/lib/qt/lib/libQtCore.so.4
#36 0xb6012ad5 in ?? () from /usr/lib/qt/lib/libQtGui.so.4
#37 0xb6a9b6e9 in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ()
   from /usr/lib/qt/lib/libQtCore.so.4
#38 0xb6a9b98a in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) ()
   from /usr/lib/qt/lib/libQtCore.so.4
#39 0xb6aa03df in QCoreApplication::exec() () from /usr/lib/qt/lib/libQtCore.so.4
#40 0xb5f5f727 in QApplication::exec() () from /usr/lib/qt/lib/libQtGui.so.4
#41 0x08091154 in runKMyMoney (a=0x8670c20, splash=0x86c0900)
    at /usr/local/src/extras/kmymoney-git/kmymoney/kmymoney/main.cpp:282
#42 0x0808faa1 in main (argc=1, argv=0xbffff244)
    at /usr/local/src/extras/kmymoney-git/kmymoney/kmymoney/main.cpp:181
(gdb)
Comment 3 Cristian Oneț 2012-01-17 12:07:44 UTC
(In reply to comment #2)
> Yes, I can reproduce it. When entering the quantity, leave the zero in the
> field, position the cursor after the zero and press 9.

Thanks, I can reproduce this now so the fix will be on it's way.
Comment 4 Cristian Oneț 2012-01-17 20:11:30 UTC
This is actually a bug in libalkimia which does not handle the leading '0's correctly.
Comment 5 Cristian Oneț 2012-01-17 20:31:25 UTC
Created attachment 67939 [details]
Patch that fixes this bug.

Thomas, I need your opinion about this. 

Also what do you think for the stable KMyMoney release: will we release another version of libalkimia and leave KMyMoney as it is or should we add a workaround in KMyMoney to cover the currently released libalkimia version?
I guess we can't change the required libalkimia version so we should add a workaround in the stable branch of KMyMoney.
Comment 6 Cristian Oneț 2012-01-17 20:38:14 UTC
Thomas I've added you the the BUGs CC because I've changed the product to libalkimia an I don't know where does the bug activity produces notifications.
Comment 7 Cristian Oneț 2012-01-17 21:23:06 UTC
Created attachment 67941 [details]
Updated patch to handle std::invalid_argument in unforeseen cases.

This way we make sure that we don't bring down the application because of an unhandled exception.
Comment 8 Thomas Baumgart 2012-01-18 07:24:35 UTC
Git commit f1cd40914e1125e0db0afed1d9439657b1fd7d6f by Thomas Baumgart.
Committed on 18/01/2012 at 08:21.
Pushed by tbaumgart into branch 'master'.

Make sure to remove leading zeroes from decimal part
so that numbers are not treated as octal when passed
to the mpq_class ctor.

M  +16   -10   libalkimia/alkvalue.cpp

http://commits.kde.org/alkimia/f1cd40914e1125e0db0afed1d9439657b1fd7d6f
Comment 9 Thomas Baumgart 2012-01-18 07:30:35 UTC
I modified the patch a bit, added it to libalkimia and move this entry back to KMyMoney.

We need to decide if we rely on a newer version of libalkimia via dependency or fix it in KMyMoney itself. I propose to use the former for KMyMoney master (which requires to release libalkimia 4.3.2) and the latter for its stable branch.
Comment 10 Cristian Oneț 2012-01-18 07:58:25 UTC
(In reply to comment #9)
> I modified the patch a bit, added it to libalkimia and move this entry back to
> KMyMoney.
> 
> We need to decide if we rely on a newer version of libalkimia via dependency or
> fix it in KMyMoney itself. I propose to use the former for KMyMoney master
> (which requires to release libalkimia 4.3.2) and the latter for its stable
> branch.

So we agree, then I'll fix the stable branch and we'll fix master after libalkimia 4.3.2 will be release.
Comment 11 Cristian Oneț 2012-01-18 18:45:28 UTC
Git commit cefc5f9d3e54fb04be4d6a984f7f2d935a1b1d29 by Cristian Oneț.
Committed on 18/01/2012 at 19:19.
Pushed by conet into branch '4.6'.

If the value can't be parsed due to leading zeros the result will be 0.
I didn't port the whole remove leading zeros feature since that will complicate
the fix and after all the goal is to avoid a crash in an unsual situation.

M  +7    -1    kmymoney/mymoney/mymoneymoney.cpp

http://commits.kde.org/kmymoney/cefc5f9d3e54fb04be4d6a984f7f2d935a1b1d29