-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Peerjs crashes if you send any Unicode characters above U+FFFF #11
Comments
Ping: Any chance someone could review my proposed js-binarypack patch? I'm satisfied it fixes the issue (it has unit tests and comprehensive comments). Thanks! |
Transferred to the binarypack-repo (issue tracker wasn't enabled before). Thank you for the bug report and the pull request! Complete with description, analysis, explanation, workaround, fix, and code for reproduction, this is probably the most helpful issue I have seen here! I could reproduce the crash and confirm your patch works. I'll merge it now, but it will take some time to reach npm. Only the previous maintainer has write-access to the package; I'll ask him to transfer it. |
Thanks very much! |
Hi @jonasgloning , is there anything we can do to get this updated in npm? Especially in the package |
Released now as |
Can you explain to me why |
Great question. A Javascript string with unpaired surrogates is not actually valid UTF-16, and so it cannot be round-tripped to UTF-8 and back. The recommended way to handle this is to replace each unpaired surrogate with \uFFFD (the "replacement character").
Note a surrogate pair means two adjacent Javascript characters where the first is in the range \uD800 - \uDBFF and the second is in the range \uDC00 - \uDFFF. To be valid UTF-16, Javascript characters from these ranges must *only* appear in surrogate pairs. An *unpaired* surrogate means any such Javascript character that is not paired up properly.
|
Steps to reproduce: Essentially, just
conn.send( '𨋢' )
using the default binary serialization. See full example below.Expected behaviour: Data is sent and received correctly.
Actual behaviour: The receiving peer crashes inside
util.unpack
, because the sender sent garbled data.Cause
This happens when sending any Unicode codepoint above U+FFFF:
'\uD860\uDEE2'
.utf8Length
wrongly assumes each individual surrogate becomes three UTF-8 bytes (i.e. a total of six bytes for a surrogate pair).util.unpack
.Fix: #10
Workaround: Using JSON serialization (instead of the default binary) avoids the crash (but has certain other disadvantages).
Full code to reproduce the error
The text was updated successfully, but these errors were encountered: