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

[ctypes][linux]ctypes.util.find_library() crash instead of return None #114257

Closed
Labels
3.11only security fixes3.12only security fixes3.13bugs and security fixestopic-ctypestype-bugAn unexpected behavior, bug, or error
@Jacobfaib

Description

@Jacobfaib

Bug report

Bug description:

The problem:

ctypes.util.find_library() raises an exception on certain inputs when it cannot find it.

Expected behavior:

No exception, returnNone asadvertised if it cannot find the library.

Reproducer:

# on python 3.10, but same deal on other versions too>>>importctypes.util>>>ctypes.util.find_library('libgomp')Traceback (mostrecentcalllast):File"<stdin>",line1,in<module>File"/path/to/lib/python3.10/ctypes/util.py",line351,infind_library_get_soname(_findLib_gcc(name))or_get_soname(_findLib_ld(name))File"/path/to/lib/python3.10/ctypes/util.py",line148,in_findLib_gccifnot_is_elf(file):File"/path/to/lib/python3.10/ctypes/util.py",line100,in_is_elfwithopen(filename,'br')asthefile:FileNotFoundError: [Errno2]Nosuchfileordirectory:b'liblibgomp.a'

Note that the crash does not occur if you put nonsense in:

  1. find_library('asdadsas') -> OK
  2. find_library('libasdasdasd') -> OK

The problem appears to be a bit more contrived. Python is attempting to parse the output from gcc, which in this case is:

/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/Scrt1.o/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/crti.o/usr/lib/gcc/x86_64-linux-gnu/12/crtbeginS.o/usr/bin/ld: cannot find -llibgomp: No such file or directory/usr/bin/ld: note to link with /usr/lib/gcc/x86_64-linux-gnu/12/libgomp.a use -l:libgomp.a or rename it to liblibgomp.a/usr/lib/gcc/x86_64-linux-gnu/12/libgcc.a/usr/lib/gcc/x86_64-linux-gnu/12/libgcc_s.so/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu/libgcc_s.so.1/usr/lib/gcc/x86_64-linux-gnu/12/libgcc.acollect2: error: ld returned 1 exit status

But then the parser is getting confused trying to parse the useful diagnostic message mentioninglibgomp.a.

Machine details (fromplatform.uname())

uname_result(system='Linux', node='iblis', release='6.5.0-14-generic', version='#14~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Nov 20 18:15:30 UTC 2', machine='x86_64')

CPython versions tested on:

3.10, 3.11, 3.12

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes3.13bugs and security fixestopic-ctypestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp