Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. maxSize argument exceeds QByteArray size limit
Forum Updated to NodeBB v4.3 + New Features

maxSize argument exceeds QByteArray size limit

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sonichyS Offline
    sonichyS Offline
    sonichy
    wrote on last edited by
    #1

    I am reading ID3V2 of mp3 file, maxSize argument exceeds QByteArray size limit occoured, and cause read all the file.
    And how to insert a QImage to QTextBrowser ?

    QTextCodec *TC = QTextCodec::codecForName("GBK");
    QFile file(filename);
    file.open(QIODevice::ReadOnly);
    QString ID3,Ver,Revision,Flag;
    bool ok;
    qint64 pos,size;
    ID3 = QString(file.read(3));
    if(ID3 == "ID3"){
        ui->textBrowser->append(ID3);
        Ver = QString::number(file.read(1).toHex().toInt(&ok,16));
        ui->textBrowser->append("Ver: " + Ver);
        Revision = QString::number(file.read(1).toHex().toInt(&ok,16));
        ui->textBrowser->append("Revision: " + Revision);
        Flag = QString::number(file.read(1).toHex().toInt(&ok,16));
        ui->textBrowser->append("Flag:" + Flag);
        size = file.read(4).toHex().toInt(&ok,16);
        ui->textBrowser->append("size: " + QString::number(size));
        while(file.pos()<size){
            QString FTag(file.read(4));
            int FSize = file.read(4).toHex().toInt(&ok,16);
            Flag = QString::number(file.read(2).toHex().toInt(&ok,16));
            QByteArray BA = file.read(FSize);
            if(FTag == "APIC"){
                QBuffer buffer(&BA);
                buffer.open(QIODevice::ReadOnly);
                QImageReader reader(&buffer,"JPG");
                QImage image = reader.read();
                image.save("cover.jpg");
            }else{
                ui->textBrowser->append(FTag + ": " + QString(TC->toUnicode(BA)));
            }
        }
    }
    

    https://github.com/sonichy

    DiracsbracketD 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What size is that ?
      Where do you get it from ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • sonichyS sonichy

        I am reading ID3V2 of mp3 file, maxSize argument exceeds QByteArray size limit occoured, and cause read all the file.
        And how to insert a QImage to QTextBrowser ?

        QTextCodec *TC = QTextCodec::codecForName("GBK");
        QFile file(filename);
        file.open(QIODevice::ReadOnly);
        QString ID3,Ver,Revision,Flag;
        bool ok;
        qint64 pos,size;
        ID3 = QString(file.read(3));
        if(ID3 == "ID3"){
            ui->textBrowser->append(ID3);
            Ver = QString::number(file.read(1).toHex().toInt(&ok,16));
            ui->textBrowser->append("Ver: " + Ver);
            Revision = QString::number(file.read(1).toHex().toInt(&ok,16));
            ui->textBrowser->append("Revision: " + Revision);
            Flag = QString::number(file.read(1).toHex().toInt(&ok,16));
            ui->textBrowser->append("Flag:" + Flag);
            size = file.read(4).toHex().toInt(&ok,16);
            ui->textBrowser->append("size: " + QString::number(size));
            while(file.pos()<size){
                QString FTag(file.read(4));
                int FSize = file.read(4).toHex().toInt(&ok,16);
                Flag = QString::number(file.read(2).toHex().toInt(&ok,16));
                QByteArray BA = file.read(FSize);
                if(FTag == "APIC"){
                    QBuffer buffer(&BA);
                    buffer.open(QIODevice::ReadOnly);
                    QImageReader reader(&buffer,"JPG");
                    QImage image = reader.read();
                    image.save("cover.jpg");
                }else{
                    ui->textBrowser->append(FTag + ": " + QString(TC->toUnicode(BA)));
                }
            }
        }
        
        DiracsbracketD Offline
        DiracsbracketD Offline
        Diracsbracket
        wrote on last edited by Diracsbracket
        #3

        @sonichy said in maxSize argument exceeds QByteArray size limit:

            int FSize = file.read(4).toHex().toInt(&ok,16);
            ...
            QByteArray BA = file.read(FSize);
        

        I assume it is this part? Have you checked the result of your FSize conversion? It is probably not what you expect.

        The max. supported size of a QByteArray seems to be 2GB. Maybe your FSize calculation results in a negative value (i.e. the MSB of the 32bit integer is being set), which if interpreted as unsigned value would exceed the max. of 2GB?

        The double conversion you are using (file.read(4).toHex().toInt(&ok,16);) seems a little bit fishy; there should be no reason to do this conversion in two steps.

        For an example on how to read binary data from an audio file header and cast it to the correct numeric value (here, a .wav file) taking into account the byte order of the binary stream, have a look at https://doc.qt.io/qt-5.10/qtmultimedia-multimedia-spectrum-app-wavfile-cpp.html.

        sonichyS 1 Reply Last reply
        4
        • DiracsbracketD Diracsbracket

          @sonichy said in maxSize argument exceeds QByteArray size limit:

              int FSize = file.read(4).toHex().toInt(&ok,16);
              ...
              QByteArray BA = file.read(FSize);
          

          I assume it is this part? Have you checked the result of your FSize conversion? It is probably not what you expect.

          The max. supported size of a QByteArray seems to be 2GB. Maybe your FSize calculation results in a negative value (i.e. the MSB of the 32bit integer is being set), which if interpreted as unsigned value would exceed the max. of 2GB?

          The double conversion you are using (file.read(4).toHex().toInt(&ok,16);) seems a little bit fishy; there should be no reason to do this conversion in two steps.

          For an example on how to read binary data from an audio file header and cast it to the correct numeric value (here, a .wav file) taking into account the byte order of the binary stream, have a look at https://doc.qt.io/qt-5.10/qtmultimedia-multimedia-spectrum-app-wavfile-cpp.html.

          sonichyS Offline
          sonichyS Offline
          sonichy
          wrote on last edited by sonichy
          #4

          @Diracsbracket Still the same error.

          qint64 FSize = file.read(4).toHex().toLongLong(&ok,16);
          

          https://github.com/sonichy

          DiracsbracketD 1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            What's the original value ?
            What's the hex value ?
            Did you check that ok's value is true ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • sonichyS sonichy

              @Diracsbracket Still the same error.

              qint64 FSize = file.read(4).toHex().toLongLong(&ok,16);
              
              DiracsbracketD Offline
              DiracsbracketD Offline
              Diracsbracket
              wrote on last edited by Diracsbracket
              #6

              @sonichy said in maxSize argument exceeds QByteArray size limit:

              Still the same error

              In addition to what @SGaist said:

              What's the original value ?
              What's the hex value ?
              Did you check that ok's value is true ?

              You could try with a dummy, known value for FSize, e.g.

              int FSize = 1024;
              QByteArray BA = file.read(FSize);
              

              @sonichy said in maxSize argument exceeds QByteArray size limit:

              qint64 FSize = file.read(4).toHex().toLongLong(&ok,16);

              Casting to a wider number format will not help if your original value is negative. In the 2-complement signed format, the MSB (i.e. the sign bit) will simply be extended and the value will still be negative in qint64 format.
              Furthermore you are still using the two-step conversion. Have you checked out the example I mentioned?

              Running the debugger and checking the value of FSize really would help.

              1 Reply Last reply
              3

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved