Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

TextIOWrapper.reconfigure() crashes if encoding is not string or None #111942

Copy link
Copy link
Closed
@serhiy-storchaka

Description

@serhiy-storchaka
Issue body actions

Crash report

What happened?

Unlike to TextIOWrapper constructor, TextIOWrapper.reconfigure() does not check that the encoding argument is actually None or string. If it is not None, it calls _PyUnicode_EqualToASCIIString that only works with strings and crashes in debug build. There may be other similar errors in other arguments.

>>> import sys
>>> sys.stdout.reconfigure(encoding=42)
Objects/unicodeobject.c:552: _PyUnicode_CheckConsistency: Assertion failed: PyType_HasFeature((Py_TYPE(((PyObject*)((op))))), ((1UL << 28)))
Enable tracemalloc to get the memory block allocation traceback

object address  : 0x55a2e3147ca8
object refcount : 4294967295
object type     : 0x55a2e3119f00
object type name: int
object repr     : 42

Fatal Python error: _PyObject_AssertFailed: _PyObject_AssertFailed
Python runtime state: initialized

Current thread 0x00007fc99ee43740 (most recent call first):
  File "<stdin>-1", line 1 in <module>
Aborted (core dumped)

CPython versions tested on:

3.10, 3.11, 3.12

Operating systems tested on:

No response

Output from running 'python -VV' on the command line:

No response

Linked PRs

Metadata

Metadata

Labels

topic-IOtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.