Skip to content

Usage of std::stof crashes on Windows when using some non-English languages/locales (i.e. German / de) #2221

Open
@taenri

Description

@taenri

Bug

If the machine's locale is set to a language like German (de) or French (fr), rendering SVG paths that contain floating point numbers will crash if the floating point numbers use dots instead of commas as the radix. This is because languages like German expect the usage of commas in floating-point numbers (i.e. ",482" instead of ".482"), and std::stof takes into account the current locale of the application. PathView utilizes std::stof in its parsing logic.

Fix recommendation: std::from_chars should be used instead as it will always use the C-default locale instead of whatever is currently set in the application. I have tested this locally and this seems to work as expected.

Environment info

As far as I know, this reproduces on Windows 11 environments in react-native-svg version 13.14.0, and the latest 14.1.0.

Steps To Reproduce

Issues without reproduction steps or code are likely to stall.

  1. Clone/build react-native-svg as normal for Windows environment.
  2. Force the locale to be German in C++ at the start of PathView::UpdateProperties via std::setlocale(LC_ALL, "de_DE");.
  3. Create a simple SVG path component with the following value for its d property: "m41.213 20.483 6.8889 3.1408m0.48227-3.8605-7.3712 0.71964 7.2985 1.2256"
  4. Build and run. Try to display SVG path from part 3.
  5. Observe that the program crashes due to invalid argument exception in PathView::ParseNumber during the std::stof call.

Describe what you expected to happen:

  1. Any SVG should render on Windows using German (de) locale and not crash. Specifically, SVGs using paths with floating-point values that use decimals for the radix instead of commas.

Short, Self Contained, Correct (Compilable), Example

N/A

If more information is needed, please let me know.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions