Solved maxSize argument exceeds QByteArray size limit
-
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))); } } }
-
Hi,
What size is that ?
Where do you get it from ? -
@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 yourFSize
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.
-
@Diracsbracket Still the same error.
qint64 FSize = file.read(4).toHex().toLongLong(&ok,16);
-
What's the original value ?
What's the hex value ?
Did you check thatok
's value is true ? -
@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.