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

A number outside int64 range is parsed as int64 min

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: P5: Not important P5: Not important
    • None
    • 6.3.1
    • Core: Serialization
    • None
    • Linux/X11

      as a user of the JSON parser, I expect that for the number -9223372036854775809 in the file, the parser shouldn't convert it to a valid int64 value - yet that's exactly what's currently happening:
      As a result, QCborValue is called with an integer type here:
      https://github.com/qt/qtbase/blob/2ad23cd72d5f122f88ce95792a4323d639c27d25/src/corelib/serialization/qjsonparser.cpp#L704

      Example:

      #include <QJsonDocument>
      #include <QJsonObject>
      #include <QJsonValue>
      #include <QDebug>
      #include <string>
      
      void parseJsonWithLargeNumbers() {
          const std::string minInt64MinusOne = R"({"value": -9223372036854775809})";
          QJsonDocument doc = QJsonDocument::fromJson(QByteArray::fromStdString(minInt64MinusOne));
          if (doc.isNull()) {
              qWarning() << "Failed to parse JSON";
              return;
          }
      
          QJsonObject obj = doc.object();
          QJsonValue value = obj["value"];
      
          // print -9223372036854775808
          if (value.isDouble()) {
              qDebug() << value.toInteger();
          }
      }
      
      int main() {
          parseJsonWithLargeNumbers();
          return 0;
      }
      

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

            thiago Thiago Macieira
            ivan-sudakov Ivan Sudakov
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes