COVESA / capicxx-someip-runtime

Common API C++ SOMEIP runtime
Mozilla Public License 2.0
111 stars 81 forks source link

Outputstream: Fix endianness issues when writing array lengths #21

Closed MarkSchmitt closed 3 years ago

MarkSchmitt commented 3 years ago

When writing a 2 or 4 byte array length (configured by arrayLengthWidth), the 16 or 32bit unsigned integer is always written as / converted to (depending on the endianness of the machine) big endian. According to the someip spec, the payload's endianness is configurable, and in the case of little endian, the serializer wrongly assumes big endian as the payloads endianness.

This causes the deserializer to read the bytes specifying the length of an array in the wrong byte order, if the payload is little endian, leading to an error on the consuming side (code is REMOTE_ERROR and not easy to track).

The program was tested solely for our own use cases, which might differ from yours.

Mark Schmitt mark.schmitt@daimler.com, Daimler TSS GmbH, imprint

MarkSchmitt commented 3 years ago

It's been a while, is there any maintainer still keeping an eye on this project?

lutzbichler commented 3 years ago

Where do I find this requirement within the (which) SOME/IP specification?

MarkSchmitt commented 3 years ago

@lutzbichler I've been using this as reference https://www.autosar.org/fileadmin/user_upload/standards/foundation/1-0/AUTOSAR_PRS_SOMEIPProtocol.pdf Page 19, Section 4.1.3 PRS_SOMEIP00369 it says The byte order of the parameters inside the payload shall be defined by configuration.. The configuration is present in the field `isLittleEndian` which is respected in the deserializer, but not in the serializer (which my patch tries to fix). Usage here by my change: https://github.com/COVESA/capicxx-someip-runtime/pull/21/commits/6a46fe8a4689d373d006f432d5ac76091dc033e2#diff-4c81b6e7390e799245076afd2b9125066fb6b2c4f727949f4bc5cc46f633c0bfR570

The deserializer already uses that field correctly: https://github.com/COVESA/capicxx-someip-runtime/blob/0ad2bdc1807fc0f078b9f9368a47ff2f3366ed13/include/CommonAPI/SomeIP/InputStream.hpp#L560