Skip to content

Cap number_of_leading_zeros in ShortNumberInfo and the JS library - #4098

Open
b84330808 wants to merge 1 commit into
google:masterfrom
b84330808:cap-leading-zeros-short-number-info
Open

b84330808 wants to merge 1 commit into
google:masterfrom
b84330808:cap-leading-zeros-short-number-info

Conversation

@b84330808

Copy link
Copy Markdown

#4010 capped number_of_leading_zeros in PhoneNumberUtil.java and phonenumberutil.cc. The same logic has three more copies that were left out, so this applies the same cap of 10 to them.

  • ShortNumberInfo.java has its own getNationalSignificantNumber(). It also lacks the > 0 check that PhoneNumberUtil.java has.
    • -1: NegativeArraySizeException
    • 500000000 with -Xmx512m: OutOfMemoryError: Java heap space
    • Integer.MAX_VALUE: OutOfMemoryError: Requested array size exceeds VM limit
  • phonenumberutil.js and shortnumberinfo.js build the zeros with Array(n + 1).join('0'). 2147483647 throws RangeError: Invalid string length.

The C++ ShortNumberInfo goes through PhoneNumberUtil::GetNationalSignificantNumber, so it's already covered and there's no C++ change here.

Bug: https://issuetracker.google.com/issues/523402884 (same issue as #4010)

Ran ShortNumberInfoTest and PhonenumberTest with javac and JUnit on JDK 17, not through Maven. PhoneNumberUtilTest wasn't run because it needs Mockito, and PhoneNumberUtil.java isn't touched. The JS tests in phonenumberutil_test.js and shortnumberinfo_test.js ran in node with google-closure-library rather than in a browser through the .html runners.

google#4010 capped number_of_leading_zeros in PhoneNumberUtil.java and
phonenumberutil.cc. The same logic has three more copies that were left out:

- ShortNumberInfo.java has its own getNationalSignificantNumber(). It also
  lacks the "> 0" check, so -1 throws NegativeArraySizeException, and large
  values throw OutOfMemoryError.
- phonenumberutil.js and shortnumberinfo.js build the zeros with
  Array(n + 1).join('0'), which throws RangeError for large values.

Use the same cap of 10 in all three. The C++ ShortNumberInfo goes through
PhoneNumberUtil, so it is already covered.

Bug: https://issuetracker.google.com/issues/523402884
@b84330808
b84330808 requested a review from a team as a code owner November 5, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant