Fix path traversal in BuildLocaleNames and uncaught parse exception in PhoneNumberTypeConverter - #428
Merged
Merged
Conversation
…n PhoneNumberTypeConverter
Found during an aggressive re-review of everything since v9.0.37:
- BuildLocaleNames wrote its per-country output file at
Path.Join(outputDir, country.Key) without the Path.GetFileName guard its
two sibling call sites in the same history got (BuildGeocoding,
BuildMetadata). country.Key comes from resources/locale/country_names.txt,
which - unlike the other resource files - is hand-generated locally rather
than copied verbatim from upstream, so it's more exposed to a bad
regeneration or manual edit writing outside outputDir. Verified the fix is
a no-op for the real data (still 249 files, same names).
- PhoneNumberTypeConverter.ConvertFrom let PhoneNumbers.NumberParseException
propagate straight out of a generic TypeConverter API on invalid input -
reproduced directly (ConvertFrom("not-a-number") threw the raw internal
exception type). Standard TypeConverter convention, and this repo's own
PhoneNumberAttribute, is to convert a failed parse into a predictable
exception rather than leak an implementation-specific type. Now wraps it
in a FormatException with the original as InnerException, with a test
covering the invalid-input path that had no coverage before.
Verified: dotnet build (0 warnings), full test suite (451/451 passing).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WVGRJyQwtvBGXAmWswxyqW
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (66.66%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #428 +/- ##
==========================================
- Coverage 87.27% 87.26% -0.02%
==========================================
Files 41 41
Lines 3828 3831 +3
Branches 978 978
==========================================
+ Hits 3341 3343 +2
- Misses 283 284 +1
Partials 204 204 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Aug 28, 2026
Closed
Open
Merged
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.
Changes
Found during an aggressive re-review of the full diff from
v9.0.37tomain(~113 files, everything since the last release — style cleanups, the metadata triage bot, benchmark CI changes, the LocaleData/LocaleNames refactor, new Extensions features).csharp/PhoneNumbers.MetadataBuilder/Program.cs:BuildLocaleNameswrote its per-country output file atPath.Join(outputDir, country.Key)without thePath.GetFileNameguard its two sibling call sites (BuildGeocoding, the metadata writer) already got elsewhere in this same range.country.Keycomes fromresources/locale/country_names.txt, which — unlike every other resource file — is hand-generated locally (lib/DumpLocale.java) rather than copied verbatim from upstream, so it's more exposed to a bad regeneration or manual edit writing outsideoutputDir. Confirmed the fix is a no-op for real data: still 249 files, same names (US,GB,CA, ...).csharp/PhoneNumbers.Extensions/PhoneNumberTypeConverter.cs:ConvertFromletPhoneNumbers.NumberParseExceptionpropagate straight out of a genericTypeConverterAPI on invalid input. Reproduced directly —ConvertFrom("not-a-number")threw the raw internal exception type. StandardTypeConverterconvention, and this repo's ownPhoneNumberAttribute(viaPhoneNumber.TryParseValid), is to convert a failed parse into a predictable outcome rather than leak an implementation-specific exception type to callers (WPF/WinForms data binding,TypeDescriptorconsumers, etc. won't be catchingPhoneNumbers.NumberParseException). Now wraps it in aFormatExceptionwith the original asInnerException, plus a test for the invalid-input path that had no coverage before.Test plan
dotnet build csharp— clean, 0 warnings.dotnet test csharp/PhoneNumbers.slnx -p:TargetFrameworks=net10.0— 451/451 passing, including the newConvertFrom_InvalidString_ThrowsFormatExceptiontest.obj/localeoutput after theBuildLocaleNamesfix — still exactly 249 files with unchanged names, confirming thePath.GetFileNamewrap is behavior-preserving for legitimate data.Generated by Claude Code