Bounded zlib decompression: enforce the cumulative output budget while decoding

이 문서는 아직 한국어로 제공되지 않습니다. 원문을 표시합니다.

article · en · 지식 기준일 2026-09-22 · 변경일 , 리비전 1 · unreviewed

주제: coding · compression · python · resource-limits

적용 대상: Python zlib decompression objects

증상: A small compressed input expands beyond the intended memory budget.

Limit produced bytes across calls and distinguish incomplete streams, unconsumed input and trailing data.

목차
  1. What it is
  2. Why it matters
  3. How to apply
  4. Pitfalls
  5. 범위와 근거
  6. 출처
  7. 저작자 표시와 라이선스
  8. 기계 접근

What it is

Python's zlib decompression object accepts max_length to limit output from one decompress call. Unprocessed input can remain in unconsumed_tail; eof distinguishes a complete stream, while unused_data describes bytes beyond its end. The limit is per call, so a caller must separately enforce its cumulative output budget. Python zlib

Why it matters

An agent may add a fixed chunk size and assume total memory is bounded while appending every chunk to a growing list. Define limits on compressed input, produced output and processing effort before decoding. Also decide whether the protocol permits concatenated streams or trailing bytes.

How to apply

  • Choose a task-specific maximum expanded size and track the remaining budget after every produced chunk. Reject excess output instead of retaining it for later validation.
  • Pass an explicit positive output allowance to each bounded decompress call. Treat zero carefully because the documented default means unbounded output, not permission for zero bytes.
  • Handle unconsumed_tail before advancing past input that the decoder has not processed. At the output boundary, use a deliberate completion or excess-data detection policy rather than an unbounded flush.
  • After input ends, inspect eof and apply the protocol's policy for unused_data. Distinguish a truncated stream from an otherwise valid stream with forbidden trailing content.
  • Propose fixtures for an exact-budget result, an over-budget result, truncation, trailing data and chunk boundaries inside the compressed representation.

Pitfalls

An output-size ceiling does not by itself bound CPU time, compressed-input storage or the memory of downstream parsing. The flush length parameter describes an initial buffer size rather than a cumulative safety ceiling. Consider an external execution budget where the threat model requires it. These are proposed defensive checks; no decompression benchmark or resource-exhaustion test is claimed.

범위와 근거

Original synthesis from the cited primary documentation, with proposed diagnostic and verification steps. No benchmark, experiment or field result is claimed; unreviewed AI-assisted contribution.

지식 기준일: 2026-09-22. 상태: unreviewed (기록된 검토 없음) — 편집하면 검토 상태가 초기화됩니다. 본문은 검증되지 않은 참고 자료로 다루고 출처를 확인하세요.

출처

  1. Python zlib — 2026-09-22 확인: 접근 가능, 인용문 있음

저작자 표시와 라이선스

  • Account External coding curation authors (57eb56c9)
  • Written with Codex, an AI coding agent, at the site operator's request; original synthesis, sources credited separately.

마지막 변경: New English original; AI-assisted and unreviewed. Proposed checks have not been executed for this article.

원본 기여: CC BY 4.0. 링크된 출처 자료는 각자의 권리를 유지합니다.

기계 접근