Guard against 0-length values
This commit is contained in:
parent
8c6344eef8
commit
64a7b0120f
1 changed files with 41 additions and 19 deletions
|
@ -76,40 +76,63 @@ QJsonValue IppMsg::consume_value(quint8 tag, Bytestream& data)
|
||||||
Q_ASSERT(false);
|
Q_ASSERT(false);
|
||||||
case Integer:
|
case Integer:
|
||||||
case Enum:
|
case Enum:
|
||||||
quint32 tmp_u32;
|
{
|
||||||
data >> tmp_len >> tmp_u32;
|
quint32 tmp_u32=0;
|
||||||
|
if(!(data >>= (quint16)0))
|
||||||
|
{
|
||||||
|
data >> (quint16)4 >> tmp_u32;
|
||||||
|
}
|
||||||
value = (int)tmp_u32;
|
value = (int)tmp_u32;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case Boolean:
|
case Boolean:
|
||||||
quint8 tmp_bool;
|
{
|
||||||
data >> tmp_len >> tmp_bool;
|
quint8 tmp_bool=0;
|
||||||
|
if(!(data >>= (quint16)0))
|
||||||
|
{
|
||||||
|
data >> (quint16)1 >> tmp_bool;
|
||||||
|
}
|
||||||
value = (bool)tmp_bool;
|
value = (bool)tmp_bool;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case DateTime:
|
case DateTime:
|
||||||
{
|
{
|
||||||
quint16 year;
|
QDateTime tmp_datetime;
|
||||||
quint8 month, day, hour, minutes, seconds, deci_seconds,
|
if(!(data >>= (quint16)0))
|
||||||
plus_minus, utc_h_offset, utc_m_offset;
|
{
|
||||||
data >> tmp_len >> year >> month >> day >> hour >> minutes >> seconds >> deci_seconds
|
quint16 year;
|
||||||
>> plus_minus >> utc_h_offset >> utc_m_offset;
|
quint8 month, day, hour, minutes, seconds, deci_seconds,
|
||||||
QDate date(year, month, day);
|
plus_minus, utc_h_offset, utc_m_offset;
|
||||||
QTime time(hour, minutes, seconds, deci_seconds*100);
|
data >> (quint16)11 >> year >> month >> day >> hour >> minutes >> seconds >> deci_seconds
|
||||||
int offset_seconds = (plus_minus == '+' ? 1 : -1)*(utc_h_offset*60*60+utc_m_offset*60);
|
>> plus_minus >> utc_h_offset >> utc_m_offset;
|
||||||
value = QDateTime(date, time, Qt::OffsetFromUTC, offset_seconds).toString(Qt::ISODate);
|
QDate date(year, month, day);
|
||||||
|
QTime time(hour, minutes, seconds, deci_seconds*100);
|
||||||
|
int offset_seconds = (plus_minus == '+' ? 1 : -1)*(utc_h_offset*60*60+utc_m_offset*60);
|
||||||
|
tmp_datetime = QDateTime(date, time, Qt::OffsetFromUTC, offset_seconds);
|
||||||
|
}
|
||||||
|
value = tmp_datetime.toString(Qt::ISODate);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Resolution:
|
case Resolution:
|
||||||
{
|
{
|
||||||
qint32 x, y;
|
qint32 x=0;
|
||||||
qint8 units;
|
qint32 y=0;
|
||||||
data >> tmp_len >> x >> y >> units;
|
qint8 units=0;
|
||||||
|
if(!(data >>= (quint16)0))
|
||||||
|
{
|
||||||
|
data >> (quint16)9 >> x >> y >> units;
|
||||||
|
}
|
||||||
value = QJsonObject {{"x", x}, {"y", y}, {"units", units}};
|
value = QJsonObject {{"x", x}, {"y", y}, {"units", units}};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case IntegerRange:
|
case IntegerRange:
|
||||||
{
|
{
|
||||||
qint32 low, high;
|
qint32 low=0;
|
||||||
data >> tmp_len >> low >> high;
|
qint32 high=0;
|
||||||
|
if(!(data >>= (quint16)0))
|
||||||
|
{
|
||||||
|
data >> (quint16)8 >> low >> high;
|
||||||
|
}
|
||||||
value = QJsonObject {{"low", low}, {"high", high}};
|
value = QJsonObject {{"low", low}, {"high", high}};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -251,7 +274,6 @@ QString IppMsg::consume_attribute(QJsonObject& attrs, Bytestream& data)
|
||||||
name = tmp_str.c_str();
|
name = tmp_str.c_str();
|
||||||
|
|
||||||
taggedValue = consume_value(tag, data);
|
taggedValue = consume_value(tag, data);
|
||||||
|
|
||||||
QJsonArray unnamed = get_unnamed_attributes(data);
|
QJsonArray unnamed = get_unnamed_attributes(data);
|
||||||
|
|
||||||
if(tag == BeginCollection)
|
if(tag == BeginCollection)
|
||||||
|
|
Loading…
Reference in a new issue