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

handle NUL/corrupt String in jspb.BinaryDecoder.prototype.readString #190

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion binary/decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,14 @@ jspb.BinaryDecoder.prototype.readString = function(length) {
var result = '';
while (cursor < end) {
var c = bytes[cursor++];
if (c < 128) { // Regular 7-bit ASCII.
if (c == 0) {
// NUL char should not occur in the middle of a String, abort decode
// We may get back in sync by avoiding malformed strings or there
// may be corruption in whatever was stored as text to begin with.
result += goog.crypt.byteArrayToString(codeUnits);
cursor=end;
continue;
} else if (c < 128) { // Regular 7-bit ASCII.
codeUnits.push(c);
} else if (c < 192) {
// UTF-8 continuation mark. We are out of sync. This
Expand Down
Loading