`<regex>`: `regex_search()` throws `regex_error(error_complexity)` with an unwisely written pattern
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- cpp
- 領域
- backend, performance, security
調査の方向性
まず、提供された regex_repro.cpp のケースを実行し、regex_search() と regex_error(error_complexity) の背後にある複雑性の処理を追跡します。既存の制限と関連するリグレッションカバレッジを特定します。このケースが例外をスローせずに false を返し、同時に病的な正規表現が過剰な処理から引き続き保護されていれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Related to #6347.
This was reported by the compiler back-end team, reduced from an important test case. This was previously accepted (MSVC Build Tools 14.50 and earlier) with regex_search() returning false (the line has been deliberately changed to contain total_WOOF_pushes so total_heap_pushes won't be found). Now with MSVC Build Tools 14.51 and later, it is rejected with a complexity exception.
D:\GitHub\STL\out\x64>type regex_repro.cpp
#include <print>
#include <regex>
#include <string>
using namespace std;
int main() {
const regex rx(R"(.*total_heap_pushes\s*:\s*(\d+) .*)");
const string line = "Router Stats: total_nets_routed: 113175 "
"total_connections_routed: 437370 "
"total_WOOF_pushes: 313639277 "
"total_heap_pops: 35866777 "
"total_internal_heap_pushes: 0 "
"total_internal_heap_pops: 0 "
"total_external_heap_pushes: 313639277 "
"total_external_heap_pops: 35866777 "
"total_external_SOURCE_pushes: 379297 "
"total_external_SOURCE_pops: 379297 "
"total_internal_SOURCE_pushes: 0 "
"total_internal_SOURCE_pops: 0 "
"rt_node_SOURCE_pushes: 379297 "
"rt_node_SOURCE_high_fanout_pushes: 3797 "
"rt_node_SOURCE_entire_tree_pushes: 375500 "
"total_external_SINK_pushes: 3488243 "
"total_external_SINK_pops: 3260194 "
"total_internal_SINK_pushes: 0 "
"total_internal_SINK_pops: 0 "
"rt_node_SINK_pushes: 0 "
"rt_node_SINK_high_fanout_pushes: 0 "
"rt_node_SINK_entire_tree_pushes: 0 "
"total_external_IPIN_pushes: 5501600 "
"total_external_IPIN_pops: 3585046 "
"total_internal_IPIN_pushes: 0 "
"total_internal_IPIN_pops: 0 "
"rt_node_IPIN_pushes: 0 "
"rt_node_IPIN_high_fanout_pushes: 0 "
"rt_node_IPIN_entire_tree_pushes: 0 "
"total_external_OPIN_pushes: 14718566 "
"total_external_OPIN_pops: 8542877 "
"total_internal_OPIN_pushes: 0 "
"total_internal_OPIN_pops: 0 "
"rt_node_OPIN_pushes: 342094 "
"rt_node_OPIN_high_fanout_pushes: 8165 "
"rt_node_OPIN_entire_tree_pushes: 333929 "
"total_external_CHANX_pushes: 143852606 "
"total_external_CHANX_pops: 10396956 "
"total_internal_CHANX_pushes: 0 "
"total_internal_CHANX_pops: 0 "
"rt_node_CHANX_pushes: 2213020 "
"rt_node_CHANX_high_fanout_pushes: 482509 "
"rt_node_CHANX_entire_tree_pushes: 1730511 "
"total_external_CHANY_pushes: 145698965 "
"total_external_CHANY_pops: 9702407 "
"total_internal_CHANY_pushes: 0 "
"total_internal_CHANY_pops: 0 "
"rt_node_CHANY_pushes: 2442282 "
"rt_node_CHANY_high_fanout_pushes: 589528 "
"rt_node_CHANY_entire_tree_pushes: 1852754 "
"total_number_of_adding_all_rt: 8814821 "
"total_number_of_adding_high_fanout_rt: 62167 "
"total_number_of_adding_all_rt_from_calling_high_fanout_rt: 41981 ";
try {
const bool found = regex_search(line, rx);
println("regex_search() returned {}.", found);
} catch (const regex_error& re) {
println("{}", re.what());
}
}
D:\GitHub\STL\out\x64>cl /EHsc /nologo /W4 /std:c++latest /MTd /Od regex_repro.cpp
regex_repro.cpp
D:\GitHub\STL\out\x64>regex_repro
regex_error(error_complexity): The complexity of an attempted match against a regular expression exceeded a pre-set level.
In this case, telling the user to fix their regex is not especially feasible. (The initial ".*" used with a regex_search() is bad and should feel bad.) I would like to retune the limits to accept this case, while still guarding against severely pathological regex DoS scenarios.
- 主要言語
- C++
- スター
- 11.2k
- フォーク
- 1.7k
- 平均マージ
- 4日 4時間
- マージ済み PR(30日)
- 14
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/STL のほかの issue
-
LWG
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 2 日以内に返信
-
generator LWG
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 2 日以内に返信
-
LWG
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 2 日以内に返信
-
`<__msvc_math.hpp>`: `_USE_MATH_DEFINES` is ignored after the first `<math.h>` include under `/Zc:cmath`対応中かも @tiagomacarios が 10 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 2 日以内に返信
似ている issue
-
c++ easy first-contributor first-contributors good first issue help wanted up-for-grabs
難易度 1/5 1〜3時間 初心者へのやさしさ 94/100
fork-commit-merge/fork-commit-merge#8709 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
-
Type: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
メンテナーはふだん 1 日以内に返信
-
bug data-types
難易度 2/5 1〜3時間 初心者へのやさしさ 71/100
ClickHouse/clickhouse-odbc#680 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
ionut-mihalache/aqua#31 · コメント 1 件 ·