<?xml version='1.0' encoding='UTF-8'?>

<!DOCTYPE rfc [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">
]>

<rfc xmlns:xi="http://www.w3.org/2001/XInclude" ipr="trust200902" docName="draft-ietf-httpbis-zstd-window-size-03" number="9659" category="info" consensus="true" submissionType="IETF" updates="8878" tocInclude="true" sortRefs="true" symRefs="true" version="3" xml:lang="en">

  <front>
    <title abbrev="Window Size for zstd">Window Sizing for Zstandard Content Encoding</title>
    <seriesInfo name="RFC" value="9659"/>
    <author initials="N." surname="Jaju" fullname="Nidhi Jaju" role="editor">
      <organization>Google</organization>
      <address>
        <postal>
          <street>Shibuya Stream, 3 Chome-21-3 Shibuya</street>
          <region>Shibuya City, Tokyo</region>
          <code>150-0002</code>
          <country>Japan</country>
        </postal>
        <email>nidhijaju@google.com</email>
      </address>
    </author>

    <author initials="W. F." surname="Handte" fullname="W. Felix P. Handte" role="editor">
      <organization>Meta Platforms, Inc.</organization>
      <address>
        <postal>
          <street>380 W 33rd St</street>
          <city>New York</city>
          <region>NY</region>
          <code>10001</code>
          <country>United States of America</country>
        </postal>
        <email>felixh@meta.com</email>
      </address>
    </author>
    <date year="2024" month="September"/>
    <area>WIT</area>
    <workgroup>httpbis</workgroup>

    <keyword>zstd</keyword>
    <keyword>zstandard</keyword>
    <keyword>compression</keyword>
    <keyword>content encoding</keyword>
    <keyword>content coding</keyword>
    <keyword>application/zstd</keyword>

    <abstract><t>Deployments of Zstandard, or "zstd", can use different window
    sizes to limit memory usage during compression and decompression. Some
    browsers and user agents limit window sizes to mitigate memory usage
    concerns, thereby causing interoperability issues. This document updates the
    window size limit in RFC 8878 from a recommendation to a requirement in
    HTTP contexts.</t>
    </abstract>
  </front>
  <middle>

<section anchor="introduction">
      <name>Introduction</name>
      <t>Zstandard, or "zstd", specified in <xref target="RFC8878"/>, is a lossless data compression
mechanism similar to gzip. When used with HTTP, the "zstd" content coding
token signals to the decoder that the content is Zstandard-compressed.</t>
      <t>An important property of Zstandard-compressed content is its Window_Size
(<xref section="3.1.1.1.2" sectionFormat="comma" target="RFC8878"/>), which describes the maximum distance for
back-references and therefore how much of the content must be kept in memory
during decompression.</t>
      <t>The minimum Window_Size is 1 KB. The maximum Window_Size is
(1&lt;&lt;41) + 7*(1&lt;&lt;38) bytes, where "&lt;&lt;" denotes a bitwise left shift, which is 3.75 TB. Larger Window_Size values tend
to improve the compression ratio but at the cost of increased memory usage.</t>
      <t>To protect against unreasonable memory usage, some browsers and user agents
limit the maximum Window_Size they will handle. This causes failures to decode
responses when the content is compressed with a larger Window_Size than the
recipient allows, leading to decreased interoperability.</t>
      <t><xref section="3.1.1.1.2" sectionFormat="comma" target="RFC8878"/> recommends that decoders support a Window_Size
of up to 8 MB, and that encoders not generate frames using a Window_Size larger
than 8 MB. However, it imposes no requirements.</t>
      <t>This document updates <xref target="RFC8878"/> to enforce Window_Size limits on the encoder
and decoder for the "zstd" HTTP content coding.</t>
    </section>
    <section anchor="conventions-and-definitions">
      <name>Conventions and Definitions</name>
        <t>
    The key words "<bcp14>MUST</bcp14>", "<bcp14>MUST NOT</bcp14>",
    "<bcp14>REQUIRED</bcp14>", "<bcp14>SHALL</bcp14>", "<bcp14>SHALL NOT</bcp14>",
    "<bcp14>SHOULD</bcp14>", "<bcp14>SHOULD NOT</bcp14>",
    "<bcp14>RECOMMENDED</bcp14>", "<bcp14>NOT RECOMMENDED</bcp14>",
    "<bcp14>MAY</bcp14>", and "<bcp14>OPTIONAL</bcp14>" in this document are to be
    interpreted as described in BCP&nbsp;14 <xref target="RFC2119"/> <xref
    target="RFC8174"/> when, and only when, they appear in all capitals, as
    shown here.
</t>
</section>
    <section anchor="window-size">
      <name>Window Size</name>
      <t>To ensure interoperability, when using the "zstd" content coding, decoders <bcp14>MUST</bcp14>
support a Window_Size of up to and including 8 MB, and encoders <bcp14>MUST NOT</bcp14>
generate frames requiring a Window_Size larger than 8 MB (see
<xref target="zstd-iana-token"/>).</t>
    </section>
    <section anchor="security-considerations">
      <name>Security Considerations</name>
      <t>This document introduces no new security considerations beyond those discussed
in <xref target="RFC8878"/>.</t>
      <t>Note that decoders still need to take into account that they can receive
oversized frames that do not follow the window size limit specified in this
document and fail decoding when such invalid frames are received.</t>
    </section>
    <section anchor="iana-considerations">
      <name>IANA Considerations</name>
      <section anchor="zstd-iana-token">
        <name>Content Encoding</name>
        <t>This document updates the following entry in the "HTTP Content
Coding Registry"
in the <eref target="https://www.iana.org/assignments/http-parameters">"Hypertext Transfer Protocol (HTTP)
Parameters" registry group</eref>:</t>
        <dl>
          <dt>Name:</dt>
          <dd>
            <t>zstd</t>
          </dd>
          <dt>Description:</dt>
          <dd>
            <t>A stream of bytes compressed using the Zstandard protocol with a Window_Size
of not more than 8 MB.</t>
          </dd>
          <dt>Reference:</dt>
          <dd>
            <t>This document and <xref target="RFC8878"/></t>
          </dd>
        </dl>
      </section>
    </section>
  </middle>
  <back>
    <references anchor="sec-normative-references">
      <name>Normative References</name>

      <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.8878.xml"/>
      <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml"/>
      <xi:include href="https://bib.ietf.org/public/rfc/bibxml/reference.RFC.8174.xml"/>

    </references>

<section numbered="false" anchor="acknowledgments">
      <name>Acknowledgments</name>
      <t>Zstandard was developed by <contact fullname="Yann Collet" />.</t>
      <t>The authors would like to thank <contact fullname="Yann Collet" />, <contact fullname="Klaus Post" />, <contact fullname="Adam Rice" />, and members
of the Web Performance Working Group in the W3C for collaborating on the window
size issue and helping to formulate a solution.</t>
    </section>
  </back>

</rfc>
