1010from pathlib import Path
1111from typing import Optional , TypeVar
1212
13+ from elftools .elf .elffile import ELFFile
14+
15+ from auditwheel .pool import POOL
16+
1317from . import json
1418from .architecture import Architecture
1519from .elfutils import (
@@ -94,19 +98,19 @@ def get_wheel_elfdata(
9498 shared_libraries_with_invalid_machine = []
9599
96100 platform_wheel = False
97- for fn , elf in elf_file_filter (ctx .iter_files ()):
98- # Check for invalid binary wheel format: no shared library should
99- # be found in purelib
100- so_name = fn .name
101101
102- # If this is in purelib, add it to the list of shared libraries in
103- # purelib
104- if any (p .name == "purelib" for p in fn .parents ):
105- shared_libraries_in_purelib .append (so_name )
102+ def inner (fn : Path ) -> None :
103+ nonlocal \
104+ platform_wheel , \
105+ shared_libraries_in_purelib , \
106+ uses_ucs2_symbols , \
107+ uses_PyFPE_jbuf
108+
109+ with open (fn , "rb" ) as f :
110+ elf = ELFFile (f )
111+
112+ so_name = fn .name
106113
107- # If at least one shared library exists in purelib, this is going
108- # to fail and there's no need to do further checks
109- if not shared_libraries_in_purelib :
110114 log .debug ("processing: %s" , fn )
111115 elftree = ldd (fn , exclude = exclude )
112116
@@ -115,11 +119,11 @@ def get_wheel_elfdata(
115119 if arch != wheel_policy .architecture .baseline :
116120 shared_libraries_with_invalid_machine .append (so_name )
117121 log .warning ("ignoring: %s with %s architecture" , so_name , arch )
118- continue
122+ return
119123 except ValueError :
120124 shared_libraries_with_invalid_machine .append (so_name )
121125 log .warning ("ignoring: %s with unknown architecture" , so_name )
122- continue
126+ return
123127
124128 platform_wheel = True
125129
@@ -148,6 +152,20 @@ def get_wheel_elfdata(
148152 # its internal references later.
149153 nonpy_elftree [fn ] = elftree
150154
155+ # Create new ELFFile object to avoid use-after-free
156+ for fn , _elf in elf_file_filter (ctx .iter_files ()):
157+ # Check for invalid binary wheel format: no shared library should
158+ # be found in purelib
159+ so_name = fn .name
160+
161+ # If this is in purelib, add it to the list of shared libraries in
162+ # purelib
163+ if any (p .name == "purelib" for p in fn .parents ):
164+ shared_libraries_in_purelib .append (so_name )
165+
166+ if not shared_libraries_in_purelib :
167+ POOL .submit (fn , inner , fn )
168+
151169 # If at least one shared library exists in purelib, raise an error
152170 if shared_libraries_in_purelib :
153171 libraries = "\n \t " .join (shared_libraries_in_purelib )
@@ -159,6 +177,8 @@ def get_wheel_elfdata(
159177 )
160178 raise RuntimeError (msg )
161179
180+ POOL .wait ()
181+
162182 if not platform_wheel :
163183 raise NonPlatformWheel (
164184 wheel_policy .architecture , shared_libraries_with_invalid_machine
0 commit comments