MixedRealityToolkit icon indicating copy to clipboard operation
MixedRealityToolkit copied to clipboard

Strings are truncated if they contain '\0' character

Open davidkalloc opened this issue 9 years ago • 2 comments

std::string is technically not 0-terminated, and so you can construct valid std::strings with '\0' characters in them. This is especially useful because you can wrap raw binary data into an std::string and still cart it around properly.

The issue is that at the network level, the Sharing library uses .c_str() to put the std::string into a RakString before sending. RakString is a 0-terminated string, so it will truncate the std::string to the 0 terminator.

The fix is to not use RakString. There are plenty of solutions, but what I chose was to send a uint32 size, and then WriteAlignedBytes for the string data. Similarly, on the read side, instead of reading a RakString, I read the uint32 size and ReadAlignedBytes into an std::string.

I have written this and it works. I can go through the hassle of branching and doing a pull request, but this is simple enough that it seems it could be fixed on your end using your own style/preferences.

NOTE: The way I did this, it caused old servers to crash, so the server has to be replaced before using.

davidkalloc avatar Apr 06 '17 02:04 davidkalloc

Would love to see the Pull Request from you for this!

jwittner avatar Apr 07 '17 20:04 jwittner

https://github.com/Microsoft/HoloToolkit/pull/81

davidkalloc avatar Apr 07 '17 22:04 davidkalloc