fix: add MAX_INPUT_STRING_LENGTH check in C++ ParseHelper#3974
Open
Tulgaaaaaaaa wants to merge 2 commits intogoogle:masterfrom
Open
fix: add MAX_INPUT_STRING_LENGTH check in C++ ParseHelper#3974Tulgaaaaaaaa wants to merge 2 commits intogoogle:masterfrom
Tulgaaaaaaaa wants to merge 2 commits intogoogle:masterfrom
Conversation
The Java and JavaScript implementations both enforce a 250-character limit on input strings before regex evaluation to prevent excessive CPU consumption. The C++ implementation was missing this check, allowing unbounded input to reach the ICU backtracking regex engine (the default build configuration). Add the same kMaxInputStringLength=250 guard at the top of ParseHelper, matching the Java implementation at PhoneNumberUtil.java:3279. Bug: CWE-1333 (ReDoS via Inefficient Regular Expression)
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Verify that inputs longer than 250 characters are rejected with NOT_A_NUMBER, matching the Java/JS MAX_INPUT_STRING_LENGTH behavior. Tests boundary at exactly 250 chars and normal parsing still works.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The C++
ParseHelper()function is missing theMAX_INPUT_STRING_LENGTHinput length check that both the Java and JavaScript implementations enforce.PhoneNumberUtil.java:70,3279):MAX_INPUT_STRING_LENGTH = 250, throwsTOO_LONGphonenumberutil.js:135,4267):MAX_INPUT_STRING_LENGTH_ = 250, throwsTOO_LONGThe default C++ build uses ICU regexp (
USE_ICU_REGEXP=ONin CMakeLists.txt:87), which is a backtracking NFA engine. Without input length bounds, long strings can cause excessive CPU consumption in regex operations.The Java source comment explicitly states the purpose (line 68-69): "We don't allow input strings for parsing to be longer than 250 chars. This prevents malicious input from overflowing the regular-expression engine."
Fix
Added
kMaxInputStringLength = 250check at the top ofParseHelper(), returningNOT_A_NUMBERfor inputs exceeding 250 characters. This matches the Java/JS behavior of rejecting oversized inputs before regex evaluation.Tests added
ParseRejectsInputLongerThanMaxLengthinphonenumberutil_test.cc