Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions tools/test_reload_under_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def wait_port(port: int, timeout: float = 10.0) -> None:
raise RuntimeError(f"nothing listening on 127.0.0.1:{port}")


def one(port: int, rid: int, zstd_bin: str) -> None:
def one(port: int, rid: int, zstd_bin: str, dict_path: pathlib.Path) -> None:
req = urllib.request.Request(
f"http://127.0.0.1:{port}/r/{rid}",
headers={"Accept-Encoding": "zstd",
Expand All @@ -141,8 +141,14 @@ def one(port: int, rid: int, zstd_bin: str) -> None:
blob = resp.read()
if blob[:4] != b"\x28\xb5\x2f\xfd":
raise RuntimeError(f"rid={rid}: no zstd magic")
r = subprocess.run([zstd_bin, "-dq", "-c"], input=blob,
capture_output=True)
# nginx.conf below sets zstd_dict_file, so every response is compressed
# against that dictionary (ZSTD_CCtx_refCDict in the filter module) --
# the decoder needs the same dictionary via -D, or libzstd correctly
# rejects the frame as "Data corruption detected" even though nothing is
# actually corrupt. Omitting -D here previously made this test fail on
# every run regardless of reload timing (any response, any size).
r = subprocess.run([zstd_bin, "-dq", "-c", "-D", str(dict_path)],
input=blob, capture_output=True)
Comment on lines +144 to +151

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu
ruff check --select PLW1510 tools/test_reload_under_load.py

Repository: myguard-labs/nginx-zstd-module

Length of output: 861


Add check=False to this subprocess.run call. The non-zero decoder exit is handled manually, and the explicit flag silences Ruff PLW1510.

🧰 Tools
🪛 ast-grep (0.44.1)

[error] 149-150: Command coming from incoming request
Context: subprocess.run([zstd_bin, "-dq", "-c", "-D", str(dict_path)],
input=blob, capture_output=True)
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

(subprocess-from-request)

🪛 Ruff (0.15.21)

[error] 150-150: subprocess call: check for execution of untrusted input

(S603)


[warning] 150-150: subprocess.run without explicit check argument

Add explicit check=False

(PLW1510)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tools/test_reload_under_load.py` around lines 144 - 151, Update the
subprocess.run invocation that decodes the response blob to explicitly pass
check=False, preserving the existing manual handling of non-zero decoder exits
and satisfying Ruff PLW1510.

Source: Linters/SAST tools

if r.returncode != 0:
raise RuntimeError(f"rid={rid}: zstd -d failed: "
+ r.stderr.decode("utf-8", "replace"))
Expand Down Expand Up @@ -235,7 +241,7 @@ def worker():
rid = counter["n"]
counter["n"] += 1
try:
one(args.port, rid, args.zstd_bin)
one(args.port, rid, args.zstd_bin, dict_path)
except Exception as e: # noqa: BLE001
failures.append(str(e))

Expand Down
Loading