10
10
from pathlib import Path
11
11
from typing import Optional , TypeVar
12
12
13
+ from elftools .elf .elffile import ELFFile
14
+
15
+ from auditwheel .pool import POOL
16
+
13
17
from . import json
14
18
from .architecture import Architecture
15
19
from .elfutils import (
@@ -94,19 +98,19 @@ def get_wheel_elfdata(
94
98
shared_libraries_with_invalid_machine = []
95
99
96
100
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
101
101
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
106
113
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 :
110
114
log .debug ("processing: %s" , fn )
111
115
elftree = ldd (fn , exclude = exclude )
112
116
@@ -115,11 +119,11 @@ def get_wheel_elfdata(
115
119
if arch != wheel_policy .architecture .baseline :
116
120
shared_libraries_with_invalid_machine .append (so_name )
117
121
log .warning ("ignoring: %s with %s architecture" , so_name , arch )
118
- continue
122
+ return
119
123
except ValueError :
120
124
shared_libraries_with_invalid_machine .append (so_name )
121
125
log .warning ("ignoring: %s with unknown architecture" , so_name )
122
- continue
126
+ return
123
127
124
128
platform_wheel = True
125
129
@@ -148,6 +152,20 @@ def get_wheel_elfdata(
148
152
# its internal references later.
149
153
nonpy_elftree [fn ] = elftree
150
154
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
+
151
169
# If at least one shared library exists in purelib, raise an error
152
170
if shared_libraries_in_purelib :
153
171
libraries = "\n \t " .join (shared_libraries_in_purelib )
@@ -159,6 +177,8 @@ def get_wheel_elfdata(
159
177
)
160
178
raise RuntimeError (msg )
161
179
180
+ POOL .wait ()
181
+
162
182
if not platform_wheel :
163
183
raise NonPlatformWheel (
164
184
wheel_policy .architecture , shared_libraries_with_invalid_machine
0 commit comments