mirror of
https://github.com/deepseek-ai/deepseek-harness.git
synced 2026-09-11 04:00:38 +00:00
fix(code-runtime-python): cap the raw frame length before JSON.parse and bound the log sink
Addresses the review's remaining two items: - FRAME_PARSE_CAP_BYTES (64 MiB) drops an fd-3 frame whose raw length exceeds it BEFORE toString/JSON.parse: the 256 MiB wire ceiling bounds the bytes, not the decoded structure, and a compact wide frame near that ceiling could decode to far more host memory. A regression test writes a 65 MiB log frame plus a normal one and asserts the oversized frame is dropped while the trailing frame still lands in logs (fail-before: without the cap the oversized text is parsed and admitted, truncating the ledger so the trailing frame is dropped). The forged-oversized lower-bound test's frame is reduced to stay under the cap while still exercising the truncation path. - The log sink writes through the def-time bound encode+write primitives (not send_sync, whose body resolves _encode_json_plain and self.write_encoded at call time), so a rebind cannot break a log frame.
This commit is contained in:
@@ -1032,8 +1032,13 @@ async def _run(channel: ProtocolChannel) -> None:
|
||||
|
||||
logs = LogBuffer(
|
||||
int(boot["maxLogBytes"]),
|
||||
sink=lambda text, truncated=False: _send_sync_cls(
|
||||
{"type": "log", "text": text, **({"truncated": True} if truncated else {})}
|
||||
# The sink writes through the def-time bound encode+write primitives
|
||||
# (not _send_sync_cls, whose body still resolves _encode_json_plain and
|
||||
# self.write_encoded at call time) so a rebind cannot break a log frame.
|
||||
sink=lambda text, truncated=False: _write_encoded_cls(
|
||||
_encode_plain_cls(
|
||||
{"type": "log", "text": text, **({"truncated": True} if truncated else {})}
|
||||
)
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user