{"record":{"id":"2944c22f396bf642","repo":"pola-rs/polars","slug":"invalid-polars-regex-size-limit","errorCode":null,"errorMessage":"invalid POLARS_REGEX_SIZE_LIMIT","messagePattern":"invalid POLARS_REGEX_SIZE_LIMIT","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/polars-utils/src/regex_cache.rs","lineNumber":13,"sourceCode":"use std::cell::RefCell;\n\nuse regex::{Regex, RegexBuilder};\n\nuse crate::cache::LruCache;\n\nfn get_size_limit() -> Option<usize> {\n    Some(\n        std::env::var(\"POLARS_REGEX_SIZE_LIMIT\")\n            .ok()\n            .filter(|l| !l.is_empty())?\n            .parse()\n            .expect(\"invalid POLARS_REGEX_SIZE_LIMIT\"),\n    )\n}\n\n// Regex compilation is really heavy, and the resulting regexes can be large as\n// well, so we should have a good caching scheme.\n//\n// TODO: add larger global cache which has time-based flush.\n\n/// A cache for compiled regular expressions.\npub struct RegexCache {\n    cache: LruCache<String, Regex>,\n    size_limit: Option<usize>,\n}\n\nimpl RegexCache {\n    fn new() -> Self {\n        Self {\n            cache: LruCache::with_capacity(32),","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-utils/src/regex_cache.rs#L1-L31","documentation":"get_size_limit reads POLARS_REGEX_SIZE_LIMIT and calls .expect(\"invalid POLARS_REGEX_SIZE_LIMIT\"), so a non-empty value that fails to parse as usize panics. This env var caps the total size of Polars' regex compilation cache.","triggerScenarios":"POLARS_REGEX_SIZE_LIMIT set to something non-numeric (e.g. '10MB', 'abc', '1_000') or negative, then triggering regex compilation through the cache (compile path) on string-matching operations.","commonSituations":"Assuming byte-size suffixes like '10MB' are accepted; thousands separators or underscores; empty var works (filtered out) but whitespace-only or garbage values do not.","solutions":["Set POLARS_REGEX_SIZE_LIMIT to a plain integer number of bytes, e.g. 10485760","Unset the variable or leave it empty to use the default cache limit","Pre-parse the value with str::parse::<usize>() in a wrapper before launch to validate","Do not use size suffixes or separators; convert units yourself"],"exampleFix":"// before\nos.environ[\"POLARS_REGEX_SIZE_LIMIT\"] = \"10MB\"\n// after\nos.environ[\"POLARS_REGEX_SIZE_LIMIT\"] = str(10 * 1024 * 1024)","handlingStrategy":"validation","validationCode":"raw = os.environ.get(\"POLARS_REGEX_SIZE_LIMIT\")\nif raw:\n    try:\n        int(raw)\n    except ValueError:\n        raise ValueError(f\"POLARS_REGEX_SIZE_LIMIT must be a plain integer (bytes), got {raw!r}\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use plain byte-count integers, no 'MB' suffixes or separators","Leave the var empty/unset to use the default","Convert units in your own config code before setting","Validate numeric env vars at application startup"],"tags":["rust","regex","environment-variable","parsing"],"backgroundTag":"invalid-env-var-value","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}