Skip to content

Qml: Don't crash when as-casting to type with errors

Such types don't have a compilation unit, but we still know their names.

Pick-to: 6.2 Fixes: QTBUG-98792 Change-Id: I2db8dea3a5a02ec1492f7f7a054fd3ad4c6ad69a Reviewed-by: Fabian Kosmale fabian.kosmale@qt.io Reviewed-by: Mitch Curtis mitch.curtis@qt.io (cherry picked from commit e0cd201e)


Was seeing exactly this crash testing kamoso on flatpak qt5.15lts-22.08.

Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007f33406fed7d in QV4::QQmlTypeWrapper::virtualInstanceOf (typeObject=<optimized out>, var=...) at qml/qqmltypewrapper.cpp:423
423             myQmlType = qenginepriv->metaObjectForType(cu->metaTypeId);
[Current thread is 1 (Thread 0x7f333a0d8dc0 (LWP 2))]
(gdb) p qenginepriv 
$1 = (QQmlEnginePrivate *) 0x55e4f97a79d0
(gdb) p cu
$2 = (QV4::ExecutableCompilationUnit *) 0x0
(gdb) where
#0  0x00007f33406fed7d in QV4::QQmlTypeWrapper::virtualInstanceOf(QV4::Object const*, QV4::Value const&) (typeObject=<optimized out>, var=<optimized out>) at qml/qqmltypewrapper.cpp:423
#1  0x00007f33405dcb77 in QV4::Object::instanceOf(QV4::Value const&) const (var=..., this=0x7ffecdca5260) at jsruntime/qv4object_p.h:370
#2  QV4::Runtime::Instanceof::call(QV4::ExecutionEngine*, QV4::Value const&, QV4::Value const&) (engine=0x55e4f965b000, lval=..., rval=...) at jsruntime/qv4runtime.cpp:387
#3  0x00007f33405c85db in QV4::Moth::VME::interpret(QV4::CppStackFrame*, QV4::ExecutionEngine*, char const*) (frame=0x7ffecdca5110, engine=0x55e4f965b000, code=0x7f33101f9cba "pL\006.\b:\tH\001\006|\b\030\t.\nL\006.\v:\fH\001\006|\tb\a\030\006\002") at jsruntime/qv4vme_moth.cpp:351
#4  0x00007f33405cd48f in QV4::Moth::VME::exec(QV4::CppStackFrame*, QV4::ExecutionEngine*) (frame=frame@entry=0x7ffecdca5340, engine=engine@entry=0x55e4f965b000) at jsruntime/qv4vme_moth.cpp:466
#5  0x00007f334055ff6e in QV4::Function::call(QV4::Value const*, QV4::Value const*, int, QV4::ExecutionContext const*) (this=this@entry=0x55e4f99a8580, thisObject=<optimized out>, argv=argv@entry=0x7f331d7c1500, argc=<optimized out>, context=<optimized out>) at jsruntime/qv4function.cpp:69
#6  0x00007f33406edb9d in QQmlJavaScriptExpression::evaluate(QV4::CallData*, bool*) (this=this@entry=0x55e4f99beb20, callData=0x7f331d7c14d0, isUndefined=isUndefined@entry=0x7ffecdca550f) at qml/qqmljavascriptexpression.cpp:212
#7  0x00007f33406f3d44 in QQmlBinding::evaluate(bool*) (this=this@entry=0x55e4f99beb20, isUndefined=isUndefined@entry=0x7ffecdca550f) at ../../include/QtQml/5.15.7/QtQml/private/../../../../../src/qml/jsruntime/qv4jscall_p.h:95
#8  0x00007f33406f7f53 in QQmlNonbindingBinding::doUpdate(QQmlJavaScriptExpression::DeleteWatcher const&, QFlags<QQmlPropertyData::WriteFlag>, QV4::Scope&) (this=0x55e4f99beb20, watcher=..., flags=..., scope=...) at qml/qqmlbinding.cpp:254
#9  0x00007f33406f5a94 in QQmlBinding::update(QFlags<QQmlPropertyData::WriteFlag>) (this=0x55e4f99beb20, flags=...) at qml/qqmlbinding.cpp:194
#10 0x00007f3340702f82 in QQmlObjectCreator::finalize(QQmlInstantiationInterrupt&) (this=0x55e4f968e5e0, interrupt=...) at qml/qqmlobjectcreator.cpp:1393
#11 0x00007f3340692ecc in QQmlComponentPrivate::complete(QQmlEnginePrivate*, QQmlComponentPrivate::ConstructionState*) (state=0x55e4f9981e28, enginePriv=0x55e4f97a79d0) at /usr/include/QtCore/qscopedpointer.h:116
#12 QQmlComponentPrivate::complete(QQmlEnginePrivate*, QQmlComponentPrivate::ConstructionState*) (enginePriv=0x55e4f97a79d0, state=0x55e4f9981e28) at qml/qqmlcomponent.cpp:996
#13 0x00007f3340694e81 in QQmlComponentPrivate::completeCreate() (this=0x55e4f9981da0) at qml/qqmlcomponent.cpp:1092
#14 0x00007f334069501d in QQmlComponent::completeCreate() (this=0x55e4f99a51c0) at qml/qqmlcomponent.cpp:1079
#15 QQmlComponent::create(QQmlContext*) (this=0x55e4f99a51c0, context=<optimized out>) at qml/qqmlcomponent.cpp:825
#16 0x00007f33406f94d5 in QQmlApplicationEnginePrivate::finishLoad(QQmlComponent*) (this=0x55e4f97a79d0, c=0x55e4f99a51c0) at qml/qqmlapplicationengine.cpp:148
#17 0x00007f33406f9ac0 in QQmlApplicationEnginePrivate::startLoad(QUrl const&, QByteArray const&, bool) (this=<optimized out>, url=<optimized out>, data=..., dataFlag=<optimized out>) at qml/qqmlapplicationengine.cpp:132
#18 0x00007f33406f9bcd in QQmlApplicationEngine::load(QUrl const&) (this=<optimized out>, url=<optimized out>) at qml/qqmlapplicationengine.cpp:287
#19 0x000055e4f8a694f6 in  ()
#20 0x000055e4f8a5c69c in  ()
#21 0x00007f333e22954a in __libc_start_call_main (main=main@entry=0x55e4f8a5c2c0, argc=argc@entry=1, argv=argv@entry=0x7ffecdca6258) at ../sysdeps/nptl/libc_start_call_main.h:58
#22 0x00007f333e22960b in __libc_start_main_impl (main=0x55e4f8a5c2c0, argc=1, argv=0x7ffecdca6258, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=<optimized out>) at ../csu/libc-start.c:389
#23 0x000055e4f8a5c965 in  ()
(gdb) 

Merge request reports