Skip to content

fix(virtual_packages): handle invalid chars in LibC family#2209

Open
ayushman1210 wants to merge 3 commits intoconda:mainfrom
ayushman1210:fix/2208
Open

fix(virtual_packages): handle invalid chars in LibC family#2209
ayushman1210 wants to merge 3 commits intoconda:mainfrom
ayushman1210:fix/2208

Conversation

@ayushman1210
Copy link
Contributor

Description

From<LibC> for GenericVirtualPackage can panic on invalid characters during package name conversion, as there was an unhandled unwrap() on string parsing.
This PR fixes the panic by removing non-alphanumeric characters, replacing them with _.

Because libc.family is arbitrary text pulled from the OS, if it contains characters that are invalid for conda package names (like spaces or parentheses), the string parsing would fail and .unwrap() would panic, completely crashing the application.

This correctly implements the TODO comment that noted the family string should be sanitized (e.g., replacing invalid characters) before converting it into a package name to prevent this panic.

Fixes #2208

How Has This Been Tested?

Added 1 unit test in crates/rattler_virtual_packages/src/lib.rs to verify that libc.family strings with parentheses and spaces are properly sanitized into package names.

cargo test -p rattler_virtual_packages

AI Disclosure

  • This PR contains AI-generated content. (The code changes and tests were drafted with the help of an AI assistant)
    • I have tested any AI-generated content in my PR.
    • I take responsibility for any AI-generated content in my PR.
      Tools: Google Gemini

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added sufficient tests to cover my changes.

@ayushman1210
Copy link
Contributor Author

hey @baszalmstra please review this pr when you have some free time and if any changes needed please let me know
thanks !!

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.

From<LibC> for GenericVirtualPackage can panic if libc.family contains invalid conda package name characters

1 participant