Javascript string decode leaves parser in a bad state if there are invalid or truncated UTF-8 characters
@lukesandberg がすでに取り組んでいます。
2022年10月7日 から。
評価
この issue はまだ評価されていません。
説明
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分
- マージ済み PR(30日)
- 2
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
protocolbuffers/protobuf-javascript のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
-
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
protocolbuffers/protobuf-javascript#248 · コメント 1 件 · リアクション 13 件 ·
-
question
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
protocolbuffers/protobuf-javascript#222 · コメント 9 件 ·
-
enhancement port-fix triaged
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
protocolbuffers/protobuf-javascript#185 · コメント 1 件 ·
-
enhancement port-fix triaged
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
protocolbuffers/protobuf-javascript#182 · コメント 3 件 · リアクション 1 件 ·
protocolbuffers/protobuf-javascript の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
antfu-collective/icones#398 ·
-
ECmail.com オープン
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
wesbos/burner-email-providers#554 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
radiantearth/stac-browser#1023 ·
-
HMR stops working オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
components-web-app/docs#92 ·