Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-21896

Crash in QScriptEngine in stringListFromArray in JSValue::toString when a cell is empty in a script

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • 4.8.3, 5.0.0
    • 4.7.4
    • Qt Script
    • None
    • qt-win-opensource-4.7.4-vs2008.exe
    • b2969c97fd808e229ff57949dbb9c683f3830b71

    Description

      When such excerpt in the Java Script is passed as an argument to C++ function

      [,"Argument Two","Argument Three"]
      

      it is called Qt SDK

      C:\Qt\4.7.4\src\script\api\qscriptengine.cpp
      QStringList QScriptEnginePrivate::stringListFromArray(JSC::ExecState *exec, JSC::JSValue arr)
      {
          QStringList lst;
          uint len = toUInt32(exec, property(exec, arr, exec->propertyNames().length));
          for (uint i = 0; i < len; ++i)
              lst.append(toString(exec, property(exec, arr, i)));
          return lst;
      }
      

      then

      C:\Qt\4.7.4\src\3rdparty\javascriptcore\JavaScriptCore\runtime\JSString.h
      
          inline UString JSValue::toString(ExecState* exec) const
          {
              if (isString())
                  return static_cast<JSString*>(asCell())->value(exec);
              if (isInt32())
                  return exec->globalData().numericStrings.add(asInt32());
              if (isDouble())
                  return exec->globalData().numericStrings.add(asDouble());
              if (isTrue())
                  return "true";
              if (isFalse())
                  return "false";
              if (isNull())
                  return "null";
              if (isUndefined())
                  return "undefined";
              ASSERT(isCell());
              return asCell()->toString(exec);                  <=this line causes crash, because asCell() returns NULL
          }
      

      There is a missing condition to check before

      return asCell()->toString(exec);
      

      because

      tag() == EmptyValueTag (-7)
      

      Regards

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kenthans Kent Hansen (Inactive)
            rkrupinski Robert
            Votes:
            2 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes