Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument is missed when the previous argument's first null falls on a %4 boundary #3

Open
uckuper opened this issue Sep 4, 2018 · 2 comments

Comments

@uckuper
Copy link

uckuper commented Sep 4, 2018

If one of the arguments of a message has the first null terminator on a divide-by-four boundary (index%4==0), then the following argument comes back as nulls. This message fails:

0x2f | 0x43 | 0x6f | 0x6e | 0x74 | 0x72 | 0x6f | 0x6c | 0x2f | 0x53 | 0x63 | 0x65 | 0x6e | 0x65 | 0x73 | 0x2f | 0x73 | 0x63 | 0x31 | 0x00 | 0x2c | 0x73 | 0x73 | 0x00 | 0x40 | 0x63 | 0x6f | 0x6e | 0x74 | 0x65 | 0x6e | 0x74 | 0x00 | 0x00 | 0x00 | 0x00 | 0x63 | 0x68 | 0x32 | 0x00

or in decimal

47 | 67 | 111 | 110 | 116 | 114 | 111 | 108 | 47 | 83 | 99 | 101 | 110 | 101 | 115 | 47 | 115 | 99 | 49 | 0 | 44 | 115 | 115 | 0 | 64 | 99 | 111 | 110 | 116 | 101 | 110 | 116 | 0 | 0 | 0 | 0 | 99 | 104 | 50 | 0

It should produce 2 arguments ("@content", "ch2") but the second one fetches nulls.

Adding this test:
if (index % 4 == 0) index++;

at line 165 of OSCPacket.cs , just before this:
while (index % 4 != 0)
index++;

seems to fix the problem, but I have not tested it extensively.

Otherwise, thank you for a very nice library!

@uckuper uckuper changed the title Argument is missed when the previous argument's first null falls on a %4 boudary Argument is missed when the previous argument's first null falls on a %4 boundary Sep 4, 2018
@uckuper
Copy link
Author

uckuper commented Sep 4, 2018

On second thought, that solution may affect arguments that are not strings. Maybe this might be more appropriate:
case('s'):
string stringVal = getString(msg, index);
arguments.Add(stringVal);
index += stringVal.Length + 1; // added 1 to account for the null
break;

@martincollett
Copy link

martincollett commented Feb 24, 2021

@uckuper thank you - I was having this problem while working with ZoomOSC, great fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants