Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions docs/developer_guide/contribution_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ Users listed in [CI_PERMISSIONS.json](https://github.com/sgl-project/sglang/blob
- If a single test file run longer than 500 seconds, split it into multiple smaller files (e.g., `test_eagle_infer_a.py`, `test_eagle_infer_b.py`).
- If a single job in a github workflow runs longer than 30 mins, split it into smaller jobs/steps.
- Reuse server launches in your unit tests to make tests run faster.
- Never use `pickle.loads()`, `pickle.load()`, or `recv_pyobj()` to deserialize untrusted or network-received data. Python's [pickle module is not secure](https://docs.python.org/3/library/pickle.html) — it can execute arbitrary code during deserialization. Use safe serialization formats such as [msgpack](https://github.com/jcrist/msgspec) or JSON instead.
- When supporting new hardware or features, follow these guidelines:
- Do not drastically change existing code.
- Always prefer new files to introduce specific components for your new hardware (e.g., `allocator_ascend.py`).
Expand Down
5 changes: 5 additions & 0 deletions python/sglang/srt/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2144,6 +2144,11 @@ def find_class(self, module, name):
)


def safe_pickle_load(fp):
"""Drop-in replacement for pickle.load() that blocks unsafe class loading."""
return SafeUnpickler(fp).load()


def debug_timing(func):
# todo: replace with a more organized instrumentation
def wrapper(*args, **kwargs):
Expand Down
5 changes: 3 additions & 2 deletions scripts/playground/replay_request_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import argparse
import glob
import json
import pickle
import time
from concurrent.futures import ThreadPoolExecutor
from dataclasses import asdict
Expand All @@ -19,6 +18,7 @@
import requests

from sglang.benchmark.utils import set_ulimit
from sglang.srt.utils.common import safe_pickle_load
from sglang.utils import get_exception_traceback


Expand Down Expand Up @@ -54,7 +54,8 @@ def normalize_request_data(json_data):
def read_records(files):
records = []
for f in files:
tmp = pickle.load(open(f, "rb"))
with open(f, "rb") as fh:
tmp = safe_pickle_load(fh)
if isinstance(tmp, dict) and "requests" in tmp:
records.extend(tmp["requests"])
else:
Expand Down
Loading