Don't copy the whole binary input into QJsonDocument

If the input binary data exceeds the size of the enclosed binary object, we
shouldn't allocate buffer and copy the whole content, but only content size
that has meaningful data.

Change-Id: I32587f504bd120c6e4e3d7e1b3403961a6f0d537
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
This commit is contained in:
Denis Dzyubenko 2012-03-29 14:59:26 +02:00 committed by Qt by Nokia
parent aeb1824a84
commit e444dcf5b1

View File

@ -237,12 +237,13 @@ QJsonDocument QJsonDocument::fromBinaryData(const QByteArray &data, DataValidati
sizeof(QJsonPrivate::Header) + root.size > (uint)data.size())
return QJsonDocument();
char *raw = (char *)malloc(data.size());
const uint size = sizeof(QJsonPrivate::Header) + root.size;
char *raw = (char *)malloc(size);
if (!raw)
return QJsonDocument();
memcpy(raw, data.constData(), data.size());
QJsonPrivate::Data *d = new QJsonPrivate::Data(raw, data.size());
memcpy(raw, data.constData(), size);
QJsonPrivate::Data *d = new QJsonPrivate::Data(raw, size);
if (validation != BypassValidation && !d->valid()) {
delete d;