Torrent example: Fix some stack overflow issues

Because of the .size() used as part of the expression it
ends up copying sizeof(qsizetype) bytes to the array,
instead of the (rationally) expected 4 bytes.

Amends 69c31f6f68

Pick-to: 6.5
Task-number: QTBUG-110622
Change-Id: I732e3f4bb5934ff3860087baa91f9bebbf044a7f
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
This commit is contained in:
Mårten Nordheim 2023-02-20 13:02:29 +01:00
parent d3c1445419
commit f3de92cdad

View File

@ -177,7 +177,7 @@ void PeerWireClient::sendPieceList(const QBitArray &bitField)
}
char message[] = {0, 0, 0, 1, 5};
qToBigEndian(bits.size() + 1, &message[0]);
qToBigEndian<qint32>(bits.size() + 1, &message[0]);
write(message, sizeof(message));
write(bits);
}
@ -227,7 +227,7 @@ void PeerWireClient::sendBlock(int piece, int offset, const QByteArray &data)
QByteArray block;
char message[] = {0, 0, 0, 1, 7};
qToBigEndian(9 + data.size(), &message[0]);
qToBigEndian<qint32>(9 + data.size(), &message[0]);
block += QByteArray(message, sizeof(message));
char numbers[4 * 2];