Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Javascript string decode leaves parser in a bad state if there are invalid or truncated UTF-8 characters

未关闭
#23 1 条评论 2 个 reaction 已指派 1 人 在 GitHub 查看

@lukesandberg 已经在做这个了。

开始于 2022年10月7日。

评估

这个 Issue 还没有评估数据。

描述

bug javascript port-fix triaged

What version of protobuf and what language are you using?
Version: v3.7.1.
Language: Javascript

What operating system (Linux, Windows, ...) and version?
Chrome

What runtime / compiler are you using (e.g., python version or gcc version)
Webpack/Typescript/Chrome

What did you do?
When a protobuf with a string field is parsed and that string field ends with an incomplete UTF8 character, readString in the binary decoder will advance the read cursor past the end of the string field, causing the rest of the message to fail to parse.

What did you expect to see
Possibly an assert in the string reader, but allow rest of message to parse correctly despite invalid content in the string field.

What did you see instead?
Usually an assert is thrown, but the error is bogus as the binary reader has advanced into field data and is trying to interpret it as field number/metadata. The error does not identify the string field that actually caused the problem.

The function is located here, in jspb.BinaryDecoder.prototype.readString:
https://github.com/protocolbuffers/protobuf/blob/master/js/binary/decoder.js#L830

The problem arises due to a combination of advancing the cursor without bounds checking:

    } else if (c < 240) { // UTF-8 with three bytes.
      var c2 = bytes[cursor++];
      var c3 = bytes[cursor++];

which can allow for cursor to advance past end. At the exit of the function, the reader's internal cursor is set:

  this.cursor_ = cursor;

At this point, cursor is a byte or two into the next field, and parsing fails.

Anything else we should know about your project / environment
The other end of this communication channel is using the C++ protobuf library, which does optionally warn but ultimately allows for potentially invalid utf-8 data to be serialized.

主要语言
JavaScript
星标
471
派生
91
平均合并
3 小时 57 分钟
30 天内合并 PR
2

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

protocolbuffers/protobuf-javascript 的其他 Issue

查看 protocolbuffers/protobuf-javascript 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。