Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

int.from_bytes crashes ifbyteorder is a string subclass #98783

Closed
Assignees
sobolevn
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)type-crashA hard crash of the interpreter, possibly with a core dump
@sobolevn

Description

@sobolevn

Here's a minimal reproduction:

» ./python.exePython 3.12.0a1+ (heads/main:bded5edd9a, Oct 27 2022, 23:29:21) [Clang 11.0.0 (clang-1100.0.33.16)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> class SubStr(str): ...... >>> int.from_bytes(b"0", SubStr("big"))Assertion failed: (PyUnicode_CheckExact(str1)), function _PyUnicode_Equal, file Objects/unicodeobject.c, line 10447.[1]    18466 abort      ./python.exe

I think this happes because of these lines:

int
_PyUnicode_Equal(PyObject*str1,PyObject*str2)
{
assert(PyUnicode_CheckExact(str1));
assert(PyUnicode_CheckExact(str2));
if (str1==str2) {
return1;
}
returnunicode_compare_eq(str1,str2);
}

_PyUnicode_Equal usesassert(PyUnicode_CheckExact(...)), while many function (includingint_from_bytes_impl) usePyUnicode_Check() or just parsestr objects from args.

elseif (_PyUnicode_Equal(byteorder,&_Py_ID(little)))
little_endian=1;
elseif (_PyUnicode_Equal(byteorder,&_Py_ID(big)))
little_endian=0;

Probably other functions that use_PyUnicode_Equal are also affected.

I would like to raise a question: shouldn't it beassert(PyUnicode_Check(...)) in_PyUnicode_Equal?

I would like to send a PR with the fix!

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-crashA 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


    [8]ページ先頭

    ©2009-2025 Movatter.jp