Skip to content

parseSignals should fail if frame data length is too small #29

Description

@TheWhiteBug

Hello. Doing some test I got what I consider unexpected results as I was sending incomplete frames; i.e. frames where the data buffer was not large enough to actually contain signal data..

Here is a draft of a patch I would like you to consider. Not certain if the check is correct but it does appear to "patch" the issue, preventing unexpected parsing success. I certainly would like to have your point of view on this.

dbc_parser_cpp$ git diff | sed 's/^M//g'
diff --git a/include/libdbc/message.hpp b/include/libdbc/message.hpp
index e903fed..b31b960 100644
--- a/include/libdbc/message.hpp
+++ b/include/libdbc/message.hpp
@@ -19,6 +19,7 @@ struct Message {
                ErrorBigEndian,
                ErrorUnknownID,
                ErrorInvalidConversion,
+               ErrorMessageTooShort, // or something...
        };

        /*!
diff --git a/src/message.cpp b/src/message.cpp
index 443526a..97233c0 100644
--- a/src/message.cpp
+++ b/src/message.cpp
@@ -31,6 +31,8 @@ Message::ParseSignalsStatus Message::parseSignals(const std::vector<uint8_t>& da
        const auto len = size * 8;
        uint64_t v = 0;
        for (const auto& signal : m_signals) {
+               if (signal.size > len)
+                       return ParseSignalsStatus::ErrorMessageTooShort;
                if (signal.is_bigendian) {
                        uint32_t start_bit = 8 * (signal.start_bit / 8) + (7 - (signal.start_bit % 8)); // Calculation taken from python CAN
                        v = data_big_endian << start_bit;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions