daniel-bytes/osc.net

MalformedMessageException maybe thrown on incorrect data validation

Opened this issue · 0 comments

HI Again

We are working further on our project where we use this great library on the server side for a temporary Device simulator.
On the client side we are using a node.js library for generating the Osc messages and sending them over UDP.
Now starting to use the Parser, we experience parsing exceptions when sending Osc messages to the simulator and it tries to parse the received message.

The exception is caused by a data length check, and I'm very curries if this is a bug in the node.js end or in this library. Hope you can help identify if the check is correct behaviour according to the spec.

So we send this message (in C type trace): /ch2/encryption\0,i\0\0\0\0\0\x01
The data length is dividable with 4
Type tags section is: ,i\0\0 which means an int will follow
Value is: 0\0\0\x01 which is the value 1
The data has no further padding or termination and according to specs then this is ok.

In the parser, at line 143, the code checks if the int chunk is to big:

if (( startPos + incrementBy ) >= data.Length) {
                throw new MalformedMessageException("Missing binary data for int32 at byte index " + startPos.ToString() + ".", data);
}

startPos + incrementBy (20 + 4) = 24
data length = 24
So it throws exception. But the data chunk is ok and removing the = from >= makes the code grab exactly those 4 bytes (index: 20, 21, 22, 23) it needs, and convert it to an int.

So the question is, is this just a bug or do the library request some extra termination of a message data array?
It seems like the same issue is on parse of float and string. It will always expect that the last typetag value has extra data after the last chunk.

Hope to get this solved. Thanks.

Best regards, Peter Meldgaard