Skip to content

gh-161924: Reject iconv encoding names with empty stripped charset - #162229

Open
Abhishekpandey123-git wants to merge 2 commits into
python:mainfrom
Abhishekpandey123-git:fix-gh-161924
Open

Abhishekpandey123-git wants to merge 2 commits into
python:mainfrom
Abhishekpandey123-git:fix-gh-161924

Conversation

@Abhishekpandey123-git

Copy link
Copy Markdown

Reject encoding names in encodings.iconv_search_function() and _codecs.iconv_{encode,decode} when the charset portion before / or , contains no ASCII alphanumeric characters.

Cause

glibc's iconv_open() strips trailing /, ,, //SUFFIX modifiers, and any non-ASCII-alphanumeric characters outside _-.,:, treating a resulting empty string as the current locale encoding. Names such as '!!!', '@', 'é', '한글', '//', and '//TRANSLIT' previously succeeded during probing and resolved to the locale codec instead of raising LookupError.

Changes

  • Require at least one ASCII alphanumeric (0-9, A-Z, a-z) in the charset portion before the first / or , in Lib/encodings/__init__.py and Modules/_codecsmodule.c.
  • Add regression tests in Lib/test/test_codecs.py (IconvTest.test_empty_stripped_charset).
  • Add a news entry.

@python-cla-bot

python-cla-bot Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant