0.21R29377 crash: Assertion failure altering Spreadsheet parameter - qstring.h line 1074

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Frank Schrüfer
Posts: 34
Joined: Sat Dec 25, 2021 12:23 pm

0.21R29377 crash: Assertion failure altering Spreadsheet parameter - qstring.h line 1074

Post by Frank Schrüfer »

Hy,

I encountered several crashes simply typing description text into the spreadsheet until I was able to see a pattern and found out how to reproduce the problem.

The crash message is:
ASSERT: "uint(i) < uint(size())" in file /usr/include/qt5/QtCore/qstring.h, line 1074

Steps to reproduce with the newest source from git 0.21R29377:
1.) Create a new Project
2.) Create a new Spreadsheet
3.) Type the two german umlaut 'öß' into any cell and press enter (us-keyboard users can copy and paste the characters)
4.) Click on the cell again, then click into the upper input textfield in order to edit the cells value
5.) Try to append a ':' character to the öß in order to get the value 'öß:' (no quotes)

My System: openSUSE Tumbleweed, VERSION="20220501"

FreeCAD language is set to german.

Thanks,
Frank
chrisb
Veteran
Posts: 53933
Joined: Tue Mar 17, 2015 9:14 am

Re: 0.21R29377 crash: Assertion failure altering Spreadsheet parameter - qstring.h line 1074

Post by chrisb »

Moved from Open discussion forum.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
chrisb
Veteran
Posts: 53933
Joined: Tue Mar 17, 2015 9:14 am

Re: 0.21R29377 crash: Assertion failure altering Spreadsheet parameter - qstring.h line 1074

Post by chrisb »

Please attach your full FreeCAD info as described in the IMPORTANT forum rules linked above.

I cannot reproduce here. I tried to leave the edit field after entering ':' with ENTER or by clicking somewhere else - no crash.

Possibly an error on its own: In the latter case the ':' is ignored, the field is left without.

Code: Select all

OS: macOS 10.16
Word size of FreeCAD: 64-bit
Version: 0.21.29321 (Git)
Build type: Release
Branch: master
Hash: 8ee773362e08d703bce9cfdcefd8e4ad424a7d44
Python 3.10.5, Qt 5.12.9, Coin 4.0.0, Vtk 9.1.0, OCC 7.5.3
Locale: C/Default (C)
Installed mods: 
  * FC_SU
  * DynamicData 2.46.0
  * FeedsAndSpeeds 0.4.0
  * fcgear
  * Manipulator 1.4.3
  * fasteners
  * sheetmetal
  * ExplodedAssembly
  * Curves 0.3.0
  * Assembly4 0.11.12
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Frank Schrüfer
Posts: 34
Joined: Sat Dec 25, 2021 12:23 pm

Re: 0.21R29377 crash: Assertion failure altering Spreadsheet parameter - qstring.h line 1074

Post by Frank Schrüfer »

Yes, it was already late at night here yesterday, but I thought I got it easy to reproduce for everybody.
Obviously not, ok, today I've been starting it via gdb and can provide additional info.

If I read the backtrace right it has something to do with expression completion:

Code: Select all

#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007ffff15d41e3 in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
#2  0x00007ffff1584306 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007ffff156d813 in __GI_abort () at abort.c:79
#4  0x00007ffff68fffae in messageHandler(QtMsgType, QMessageLogContext const&, QString const&) (type=QtFatalMsg, context=..., msg=...)
    at /home/system/usr/FreeCAD/src/src/Gui/Application.cpp:1712
#5  0x00007ffff1e5ea60 in qt_message_print(QtMsgType, QMessageLogContext const&, QString const&) (msgType=QtFatalMsg, context=..., message=...)
    at global/qlogging.cpp:1843
#6  0x00007ffff1e5eb79 in qt_message(QtMsgType, const QMessageLogContext &, const char *, typedef __va_list_tag __va_list_tag *)
    (msgType=QtFatalMsg, context=..., msg=<optimized out>, ap=<optimized out>) at global/qlogging.cpp:378
#7  0x00007ffff1e2bfbe in QMessageLogger::fatal(char const*, ...) const
    (this=this@entry=0x7fffffffa708, msg=msg@entry=0x7ffff212d000 "ASSERT: \"%s\" in file %s, line %d") at global/qlogging.cpp:890
#8  0x00007ffff1e2b45c in qt_assert(char const*, char const*, int) (assertion=<optimized out>, file=<optimized out>, line=<optimized out>)
    at global/qglobal.cpp:3358
#9  0x00007ffff6a52552 in QString::operator[](int) const (this=0x7fffffffaa18, i=3) at /usr/include/qt5/QtCore/qstring.h:1074
#10 0x00007ffff6a50450 in Gui::ExpressionCompleter::slotUpdate(QString const&, int) (this=0x5979370, prefix=..., pos=3)
    at /home/system/usr/FreeCAD/src/src/Gui/ExpressionCompleter.cpp:511
#11 0x00007ffff6a51b1d in Gui::ExpressionCompleter::qt_static_metacall(QObject*, QMetaObject::Call, int, void**)
    (_o=0x5979370, _c=QMetaObject::InvokeMetaMethod, _id=0, _a=0x7fffffffa9d0)
    at /home/system/usr/FreeCAD/bin/build/src/Gui/FreeCADGui_autogen/include/moc_ExpressionCompleter.cpp:75
#12 0x00007ffff2082488 in doActivate<false>(QObject*, int, void**) (sender=0x508f660, signal_index=14, argv=0x7fffffffa9d0)
    at kernel/qobject.cpp:3898
#13 0x00007ffff6a51f42 in Gui::ExpressionLineEdit::textChanged2(QString, int) (this=0x508f660, _t1=..., _t2=3)
    at /home/system/usr/FreeCAD/bin/build/src/Gui/FreeCADGui_autogen/include/moc_ExpressionCompleter.cpp:244
#14 0x00007ffff6a50d7b in Gui::ExpressionLineEdit::slotTextChanged(QString const&) (this=0x508f660, text=...)
    at /home/system/usr/FreeCAD/src/src/Gui/ExpressionCompleter.cpp:621
#15 0x00007ffff6a51cfb in Gui::ExpressionLineEdit::qt_static_metacall(QObject*, QMetaObject::Call, int, void**)
    (_o=0x508f660, _c=QMetaObject::InvokeMetaMethod, _id=1, _a=0x7fffffffab70)
    at /home/system/usr/FreeCAD/bin/build/src/Gui/FreeCADGui_autogen/include/moc_ExpressionCompleter.cpp:184
#16 0x00007ffff2082488 in doActivate<false>(QObject*, int, void**) (sender=0x508f660, signal_index=8, argv=0x7fffffffab70)
    at kernel/qobject.cpp:3898
#17 0x00007ffff207b7af in QMetaObject::activate(QObject*, QMetaObject const*, int, void**)
    (sender=<optimized out>, m=m@entry=0x7ffff3121b40 <QLineEdit::staticMetaObject>, local_signal_index=local_signal_index@entry=1, argv=argv@ent--Type <RET> for more, q to quit, c to continue without paging--
ry=0x7fffffffab70) at kernel/qobject.cpp:3946
#18 0x00007ffff2d43f45 in QLineEdit::textEdited(QString const&) (this=<optimized out>, _t1=<optimized out>) at .moc/moc_qlineedit.cpp:454
#19 0x00007ffff2d41544 in QLineEditPrivate::_q_textEdited(QString const&) (this=0x1a0f020, text=<optimized out>) at widgets/qlineedit_p.cpp:132
#20 0x00007ffff2082488 in doActivate<false>(QObject*, int, void**) (sender=0x634c740, signal_index=7, argv=0x7fffffffac80)
    at kernel/qobject.cpp:3898
#21 0x00007ffff207b7af in QMetaObject::activate(QObject*, QMetaObject const*, int, void**)
    (sender=sender@entry=0x634c740, m=m@entry=0x7ffff3121c00 <QWidgetLineControl::staticMetaObject>, local_signal_index=local_signal_index@entry=4, argv=argv@entry=0x7fffffffac80) at kernel/qobject.cpp:3946
#22 0x00007ffff2d4b495 in QWidgetLineControl::textEdited(QString const&) (this=this@entry=0x634c740, _t1=...)
    at .moc/moc_qwidgetlinecontrol_p.cpp:280
#23 0x00007ffff2d4eb9b in QWidgetLineControl::finishChange(int, bool, bool)
    (this=0x634c740, validateFromState=<optimized out>, update=<optimized out>, edited=<optimized out>) at widgets/qwidgetlinecontrol.cpp:735
#24 0x00007ffff2d517f4 in QWidgetLineControl::processKeyEvent(QKeyEvent*) (this=0x634c740, event=event@entry=0x7fffffffb610)
    at widgets/qwidgetlinecontrol.cpp:1943
#25 0x00007ffff2d4403b in QLineEdit::keyPressEvent(QKeyEvent*) (this=0x508f660, event=0x7fffffffb610) at widgets/qlineedit.cpp:1794
#26 0x00007ffff6a50fc2 in Gui::ExpressionLineEdit::keyPressEvent(QKeyEvent*) (this=0x508f660, e=0x7fffffffb610)
    at /home/system/usr/FreeCAD/src/src/Gui/ExpressionCompleter.cpp:641
#27 0x00007ffff2c3fb68 in QWidget::event(QEvent*) (this=0x508f660, event=0x7fffffffb610) at kernel/qwidget.cpp:8679
#28 0x00007ffff2bfcb0f in QApplicationPrivate::notify_helper(QObject*, QEvent*)
    (this=this@entry=0x58d220, receiver=receiver@entry=0x508f660, e=e@entry=0x7fffffffb610) at kernel/qapplication.cpp:3632
#29 0x00007ffff2c0474e in QApplication::notify(QObject*, QEvent*) (this=<optimized out>, receiver=0x508f660, e=0x7fffffffb610)
    at kernel/qapplication.cpp:2994
#30 0x00007ffff6a560a8 in Gui::GUIApplication::notify(QObject*, QEvent*) (this=0x7fffffffc2c0, receiver=0x508f660, event=0x7fffffffb610)
    at /home/system/usr/FreeCAD/src/src/Gui/GuiApplication.cpp:84
#31 0x00007ffff204bb5a in QCoreApplication::notifyInternal2(QObject*, QEvent*) (receiver=0x508f660, event=0x7fffffffb610)
    at kernel/qcoreapplication.cpp:1064
#32 0x00007ffff2c5b24f in QWidgetWindow::event(QEvent*) (this=0x186ead0, event=0x7fffffffb610) at kernel/qwidgetwindow.cpp:293
#33 0x00007ffff2bfcb0f in QApplicationPrivate::notify_helper(QObject*, QEvent*) (this=<optimized out>, receiver=0x186ead0, e=0x7fffffffb610)
    at kernel/qapplication.cpp:3632
#34 0x00007ffff6a560a8 in Gui::GUIApplication::notify(QObject*, QEvent*) (this=0x7fffffffc2c0, receiver=0x186ead0, event=0x7fffffffb610)
    at /home/system/usr/FreeCAD/src/src/Gui/GuiApplication.cpp:84
#35 0x00007ffff204bb5a in QCoreApplication::notifyInternal2(QObject*, QEvent*) (receiver=0x186ead0, event=0x7fffffffb610)
    at kernel/qcoreapplication.cpp:1064
--Type <RET> for more, q to quit, c to continue without paging--
#36 0x00007ffff24a6bf2 in QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyEvent*) (e=0x50b05b0)
    at kernel/qguiapplication.cpp:2414
#37 0x00007ffff248086c in QWindowSystemInterface::sendWindowSystemEvents(QFlags<QEventLoop::ProcessEventsFlag>) (flags=flags@entry=...)
    at kernel/qwindowsysteminterface.cpp:1169
#38 0x00007fffec85ce9a in xcbSourceDispatch(GSource*, GSourceFunc, gpointer) (source=source@entry=0x7ff6d0) at qxcbeventdispatcher.cpp:105
#39 0x00007ffff0837122 in g_main_dispatch (context=0x7fffe4005010) at ../glib/gmain.c:3417
#40 g_main_context_dispatch (context=0x7fffe4005010) at ../glib/gmain.c:4135
#41 0x00007ffff08374b8 in g_main_context_iterate
    (context=context@entry=0x7fffe4005010, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../glib/gmain.c:4211
#42 0x00007ffff083756f in g_main_context_iteration (context=0x7fffe4005010, may_block=1) at ../glib/gmain.c:4276
#43 0x00007ffff20a32b4 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) (this=0x80bcd0, flags=...)
    at kernel/qeventdispatcher_glib.cpp:423
#44 0x00007ffff204a55b in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) (this=this@entry=0x7fffffffb8a0, flags=..., flags@entry=...)
    at ../../include/QtCore/../../src/corelib/global/qflags.h:69
#45 0x00007ffff2052820 in QCoreApplication::exec() () at ../../include/QtCore/../../src/corelib/global/qflags.h:121
#46 0x00007ffff6902d57 in Gui::Application::runApplication() () at /home/system/usr/FreeCAD/src/src/Gui/Application.cpp:2282
#47 0x000000000040c43f in main(int, char**) (argc=1, argv=0x7fffffffd4f8) at /home/system/usr/FreeCAD/src/src/Main/MainGui.cpp:285
My version info:

Code: Select all

OS: openSUSE Tumbleweed (KDE//usr/share/xsessions/plasma5)
Word size of FreeCAD: 64-bit
Version: 0.21.29377 (Git)
Build type: Release
Branch: master
Hash: 75d8371d2bb2c2ee5c9583d848390e4c79ee9ace
Python 3.8.13, Qt 5.15.2, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.1
Locale: German/Germany (de_DE)
Installed mods: 
  * 3DfindIT 1.2.0
  * AirPlaneDesign 0.4.0
  * BIM 2021.12.0
  * BOLTSFC
  * Beltrami 1.0.6-alpha
  * CADExchanger
  * CommandPanel
  * CubeMenu
  * CurvedShapes 1.0.3
  * Curves 0.4.2
  * Defeaturing
  * Design456
  * DesignSPHysics 0.6.1-2201-31-01
  * DynamicData 2.46.0
  * EM
  * ExplodedAssembly
  * FEM_FrontISTR 0.1.0
  * GDML 1.8.0
  * IconThemes
  * ImportNURBS
  * InventorLoader 1.3.0
  * LCInterlocking
  * Lithophane
  * MakerWorkbench
  * OSE3dPrinter
  * dodo
  * fcgear 1.0.0
  * frame
  * lattice2 1.0.0
  * nurbs
  * ose-piping
  * parts_library
  * pcb
  * Autoload
  * POV-Ray-Rendering
  * Pyramids-and-Polyhedrons
  * pyrate
  * ose-workbench-core-master
  * Glass
  * Help 1.0.0-alpha
  * MeshRemodel 1.8919.0
  * Reinforcement 0.1.0
  * OpticsWorkbench 0.1.0
  * Plot 0.1.0
  * MnesarcoUtils 0.1.0
  * Manipulator 0.1.0
  * Assembly4 0.1.0
  * fasteners 0.3.40
  * Marz 0.3.40
Frank Schrüfer
Posts: 34
Joined: Sat Dec 25, 2021 12:23 pm

Re: 0.21R29377 crash: Assertion failure altering Spreadsheet parameter - qstring.h line 1074

Post by Frank Schrüfer »

P.S.: My FreeCAD build was configured with:

Code: Select all

cmake ../../src -DCMAKE_BUILD_TYPE=DEBUG -DCMAKE_C_FLAGS_DEBUG="-g -O0" -DCMAKE_CXX_FLAGS_DEBUG="-g -O0"
So maybe that is what makes my version crash with assertion failure and leaves you just with the program appearing to ignore the typed letter as the failure is catched and silently ignored.
chrisb
Veteran
Posts: 53933
Joined: Tue Mar 17, 2015 9:14 am

Re: 0.21R29377 crash: Assertion failure altering Spreadsheet parameter - qstring.h line 1074

Post by chrisb »

Thanks for helping to find the source of the crash. Please note that I have a different OS.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: 0.21R29377 crash: Assertion failure altering Spreadsheet parameter - qstring.h line 1074

Post by openBrain »

Frank Schrüfer wrote: Fri Jul 01, 2022 8:13 am P.S.: My FreeCAD build was configured with:

Code: Select all

cmake ../../src -DCMAKE_BUILD_TYPE=DEBUG -DCMAKE_C_FLAGS_DEBUG="-g -O0" -DCMAKE_CXX_FLAGS_DEBUG="-g -O0"
So maybe that is what makes my version crash with assertion failure and leaves you just with the program appearing to ignore the typed letter as the failure is catched and silently ignored.
I can confirm the crash. Will build last version and analyze.
The different behavior (from @chrisb) can be due to build in debug mode. There is something strange about this though : according your configuration flags, you do a DEBUG build, but your FC info reports a RELEASE one. :?
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: 0.21R29377 crash: Assertion failure altering Spreadsheet parameter - qstring.h line 1074

Post by openBrain »

OK, so the problem is here : https://github.com/FreeCAD/FreeCAD/blob ... r.cpp#L481
'prefixEnd' is reevaluated to a value that is greater than 'prefix.size()', which breaks here (3rd assessment) : https://github.com/FreeCAD/FreeCAD/blob ... r.cpp#L511

My problem now is that I have no clue what this block does (comment not very helpful on my side) : https://github.com/FreeCAD/FreeCAD/blob ... #L474-L484

So we could just add a check and do whatever we want, but likely it will break something else in the behavior. :)
Frank Schrüfer
Posts: 34
Joined: Sat Dec 25, 2021 12:23 pm

Re: 0.21R29377 crash: Assertion failure altering Spreadsheet parameter - qstring.h line 1074

Post by Frank Schrüfer »

openBrain wrote: Mon Jul 04, 2022 8:51 am OK, so the problem is here : https://github.com/FreeCAD/FreeCAD/blob ... r.cpp#L481
'prefixEnd' is reevaluated to a value that is greater than 'prefix.size()', which breaks here (3rd assessment) : https://github.com/FreeCAD/FreeCAD
Well, I'm not even sure what language this is, but looking at the code from my programming experience it looks like that the problem might arise from 'prefix' and the tokens having different encoding.
So maybe a character like 'ö' in the QString typed prefix is decoded to something like 'xy' as prefix might be in unicode and the tokens / std strings in something that can't represent the character or some other encoding problem of the like. The result would be that lengths of the tokens differ from the original in 'prefix'.

I'd suggest to check what 'prefix' is decoded to by 'toStdString'.

Just guessing though.

Thanks for investigating,
Frank
wmayer
Founder
Posts: 20243
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: 0.21R29377 crash: Assertion failure altering Spreadsheet parameter - qstring.h line 1074

Post by wmayer »

I'd suggest to check what 'prefix' is decoded to by 'toStdString'.
Yes, that's the basic problem. The author of the code makes the assumption that the size of "prefix" is equal to the size of "expression" but this is incorrect.
The function toStdString() encodes the QString as UTF-8 and the expression "öß:" becomes "\xc3\xb6\xc3\x9f:" (it's a string with 5 characters):

Code: Select all

"öß:".encode("utf-8") # => b'\xc3\xb6\xc3\x9f:'
len("öß:".encode("utf-8")) # => 5
Post Reply