Skip to content

Commit 3397a3e

Browse files
committed
fix: address codeql alerts on raises, tar links, and duplicate tests
1 parent b031fb1 commit 3397a3e

6 files changed

Lines changed: 24 additions & 26 deletions

File tree

‎runpod/apps/api.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ async def _execute(
4141
# transport-level failures (ssl hiccups, resets, dns)
4242
# are transient; graphql/auth errors propagate untouched
4343
last_exc = exc
44-
raise last_exc # type: ignore[misc]
44+
assert last_exc is not None # loop always runs at least once
45+
raise last_exc
4546

4647
# -- endpoints (dev session provisioning) --
4748

‎runpod/apps/targets.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ async def _request_json(
184184
# decided retryability
185185
last_exc = exc
186186
continue
187-
raise last_exc # type: ignore[misc]
187+
assert last_exc is not None # loop always runs at least once
188+
raise last_exc
188189

189190

190191
async def _post_json(

‎runpod/apps/tasks.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ async def poll_result(self) -> Optional[Dict[str, Any]]:
281281
"""
282282
url = f"{_proxy_url(self.pod_id)}/result"
283283
attempts = 6
284+
data: Dict[str, Any] = {}
284285
async with aiohttp.ClientSession() as session:
285286
for attempt in range(attempts):
286287
async with session.get(

‎runpod/runtimes/bootstrap.py‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,28 @@ def _locate():
117117
# and absolute paths
118118
tar.extractall(path=APP_DIR, filter="data")
119119
else:
120-
for member in tar.getmembers():
120+
members = tar.getmembers()
121+
for member in members:
121122
dest = os.path.realpath(
122123
os.path.join(APP_DIR, member.name)
123124
)
124125
if not dest.startswith(target + os.sep) and dest != target:
125126
raise PhaseError(
126127
"locate", f"unsafe tar member path: {member.name}"
127128
)
128-
tar.extractall(path=APP_DIR)
129+
# links can point outside and later members write
130+
# through them; artifacts never contain links
131+
if member.issym() or member.islnk():
132+
raise PhaseError(
133+
"locate",
134+
f"unsafe tar link member: {member.name}",
135+
)
136+
if not (member.isfile() or member.isdir()):
137+
raise PhaseError(
138+
"locate",
139+
f"unsupported tar member type: {member.name}",
140+
)
141+
tar.extractall(path=APP_DIR, members=members) # noqa: S202 - members validated above
129142
except (OSError, tarfile.TarError) as exc:
130143
raise PhaseError("locate", f"failed to extract artifact: {exc}")
131144

‎tests/test_apps/test_model.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,12 @@ def test_task_decorator_rejects_model(self):
7272

7373
app = App("modeltest")
7474

75+
# model= is not a parameter of @app.task; passed via a kwargs
76+
# dict so the intentional misuse is constructed at runtime
77+
kwargs = {"name": "train", "gpu": "4090", "model": Model("org/name")}
7578
with pytest.raises(TypeError, match="model"):
7679

77-
@app.task(name="train", gpu="4090", model=Model("org/name"))
80+
@app.task(**kwargs)
7881
def train():
7982
pass
8083

‎tests/test_apps/test_tasks.py‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -472,27 +472,6 @@ async def test_execute_timeout(self):
472472
await execution.execute({"fn": "t"}, timeout=10)
473473

474474

475-
class TestUnwrapTaskResponse:
476-
def test_failure_raises(self):
477-
from runpod.apps.errors import RemoteExecutionError
478-
from runpod.apps.tasks import unwrap_task_response
479-
480-
with pytest.raises(RemoteExecutionError, match="worker oom"):
481-
unwrap_task_response({"success": False, "error": "worker oom"})
482-
483-
def test_json_result(self):
484-
from runpod.apps.tasks import unwrap_task_response
485-
486-
assert unwrap_task_response(
487-
{"success": True, "json_result": {"x": 1}}
488-
) == {"x": 1}
489-
490-
def test_pickled_result(self):
491-
from runpod.apps.tasks import unwrap_task_response
492-
493-
assert unwrap_task_response({"success": True, "result": _b64(7)}) == 7
494-
495-
496475
class TestTaskJob:
497476
def _job(self):
498477
from runpod.apps.tasks import TaskExecution, TaskJob

0 commit comments

Comments
 (0)