Skip to content

Commit

Permalink
iop parsing: make the PictureObject data size check less restricitve
Browse files Browse the repository at this point in the history
The standard says: "If the data are longer than expected after all of
the rows and columns of pixels have been defined, then the VT shall
ignore all extra data bytes." So the parsed raw data size does not need
to be equal to the image dimension it could be bigger.

I also came across an implement (Kverneland Andex1304) which contains a
PictureGraphics with 0x0 actual size and 0 raw data size.
Later it also contained it later with correct dimensions, but the parser
bailed out on the first zero size.
  • Loading branch information
martonmiklos committed Jan 8, 2025
1 parent bbac440 commit 8a7fe7b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions isobus/src/isobus_virtual_terminal_working_set_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2210,12 +2210,14 @@ namespace isobus
{
if (iopLength >= tempObject->get_number_of_bytes_in_raw_data())
{
std::uint32_t dataCounter = 0;
switch (tempObject->get_format())
{
case PictureGraphic::Format::EightBitColour:
{
tempObject->set_raw_data(iopData, tempObject->get_number_of_bytes_in_raw_data());
iopData += tempObject->get_number_of_bytes_in_raw_data();
dataCounter += tempObject->get_number_of_bytes_in_raw_data();
iopLength -= tempObject->get_number_of_bytes_in_raw_data();
}
break;
Expand Down Expand Up @@ -2244,6 +2246,7 @@ namespace isobus
lineAmountLeft = tempObject->get_actual_width();
}
iopData++;
dataCounter++;
iopLength--;
}
}
Expand Down Expand Up @@ -2271,11 +2274,18 @@ namespace isobus
lineAmountLeft = tempObject->get_actual_width();
}
iopData++;
dataCounter++;
iopLength--;
}
}
break;
}

if (dataCounter < tempObject->get_number_of_bytes_in_raw_data())
{
iopData += (tempObject->get_number_of_bytes_in_raw_data() - dataCounter);
iopLength += (tempObject->get_number_of_bytes_in_raw_data() - dataCounter);
}
}
else
{
Expand All @@ -2294,9 +2304,7 @@ namespace isobus
CANStackLogger::warn("[WS]: Skipped parsing macro reference in picture graphic object (todo)");
}

if ((0 != tempObject->get_actual_width()) &&
(0 != tempObject->get_actual_height()) &&
(tempObject->get_raw_data().size() == (tempObject->get_actual_width() * tempObject->get_actual_height())))
if (tempObject->get_raw_data().size() <= (tempObject->get_actual_width() * tempObject->get_actual_height()))
{
retVal = true;
}
Expand Down

0 comments on commit 8a7fe7b

Please sign in to comment.