<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE rfc [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">
]>
<?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
<!-- generated by https://github.com/cabo/kramdown-rfc version 1.7.7 (Ruby 3.2.2) -->
<rfc xmlns:xi="http://www.w3.org/2001/XInclude" ipr="trust200902" docName="draft-jaju-httpbis-zstd-window-size-00" category="info" consensus="true" submissionType="IETF" tocInclude="true" sortRefs="true" symRefs="true" version="3">
  <!-- xml2rfc v2v3 conversion 3.20.0 -->
  <front>
    <title abbrev="Zstd Window Size">Window Sizing for Zstandard Content Encoding</title>
    <seriesInfo name="Internet-Draft" value="draft-jaju-httpbis-zstd-window-size-00"/>
    <author fullname="Nidhi Jaju">
      <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 fullname="W. Felix P. Handte">
      <organization>Meta Platforms, Inc.</organization>
      <address>
        <postal>
          <street>380 W 33rd St</street>
          <city>New York, NY 10001</city>
          <country>US</country>
        </postal>
        <email>felixh@meta.com</email>
      </address>
    </author>
    <date year="2024" month="March" day="04"/>
    <area>Web and Internet Transport</area>
    <workgroup>HTTPBIS</workgroup>
    <keyword>zstd</keyword>
    <keyword>zstandard</keyword>
    <keyword>compression</keyword>
    <keyword>content encoding</keyword>
    <keyword>application/zstd</keyword>
    <abstract>
      <?line 50?>

<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, causing interoperability
issues. This document updates the window size limit in RFC8878 from a
recommendation to a requirement in HTTP contexts.</t>
    </abstract>
    <note removeInRFC="true">
      <name>About This Document</name>
      <t>
        The latest revision of this draft can be found at <eref target="https://nidhijaju.github.io/draft-zstd-window-size/draft-jaju-httpbis-zstd-window-size.html"/>.
        Status information for this document may be found at <eref target="https://datatracker.ietf.org/doc/draft-jaju-httpbis-zstd-window-size/"/>.
      </t>
      <t>
        Discussion of this document takes place on the
        HTTPBIS Working Group mailing list (<eref target="mailto:ietf-http-wg@w3.org"/>),
        which is archived at <eref target="https://lists.w3.org/Archives/Public/ietf-http-wg/"/>.
      </t>
      <t>Source for this draft and an issue tracker can be found at
        <eref target="https://github.com/nidhijaju/draft-zstd-window-size"/>.</t>
    </note>
  </front>
  <middle>
    <?line 59?>

<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 Encoding
token signals to the decoder that the content is Zstandard-compressed.</t>
      <t>Deployments of Zstandard can use different window sizes to configure the maximum
memory a decoder requires to decompress a frame. Larger window sizes tend to
improve the compression ratio, but cause more memory to be used. <xref target="RFC8878"/>
provides a recommendation for decoders to support window sizes up to 8 MB, and
for encoders to not generate frames requiring window sizes larger than 8 MB.
However, it is just a recommendation (<xref section="3.1.1.1.2" sectionFormat="comma" target="RFC8878"/>).</t>
      <t>To protect against unreasonable memory usage, some browsers and user agents
limit the maximum window size allowed. This causes incompatibilities if the
content is compressed with a larger limit, leading to decreased interoperability.</t>
      <t>This document updates <xref target="RFC8878"/> to specify a window size limit associated with
the "zstd" Content Encoding token.</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 14 <xref target="RFC2119"/> <xref target="RFC8174"/> when, and only when, they
appear in all capitals, as shown here.</t>
      <?line -18?>

</section>
    <section anchor="window-size">
      <name>Window Size</name>
      <t>Section 3.1.1.1.2 of <xref target="RFC8878"/> discusses window sizes in Zstandard.
The window size provides guarantees about the minimum memory buffer required to
decompress a frame. This information is important for decoders to allocate
enough memory.</t>
      <t>The minimum window size is 1 KB. The maximum window size is (1&lt;&lt;41) +
7*(1&lt;&lt;38) bytes, which is 3.75 TB.</t>
      <t>In general, larger window size values tend to improve the compression ratio, but
at the cost of increased memory usage.</t>
      <t>To properly decode compressed data, a decoder will need to allocate a buffer of
at least the window size bytes.</t>
      <t>In order to protect decoders from unreasonable memory requirements, a decoder is
allowed to reject a compressed frame that requests a memory size beyond the
decoder's authorized range.</t>
      <t>To maintain interoperability of Zstandard in HTTP Content Encoding, decoders
<bcp14>MUST</bcp14> support window sizes of up to and including 8 MB and encoders <bcp14>MUST NOT</bcp14>
generate frames requiring a window size of larger than 8 MB, when using the
"zstd" Content Encoding token (see <xref target="zstd-iana-token"/>).</t>
      <t>Decoders are free to support higher or lower limits, depending on local
limitations, if negotiated out-of-band. Many deployments of Zstandard operate in controlled, private environments and can directly communicate with their encoder
and decoder to negotiate a higher or lower limit.</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>
    </section>
    <section anchor="iana-considerations">
      <name>IANA Considerations</name>
      <section anchor="zstd-iana-token">
        <name>Content Encoding</name>
        <t>This document updates the entry added in <xref target="RFC8878"/> to the "HTTP Content
Coding Registry" within the "Hypertext Transfer Protocol (HTTP) Parameters"
registry:</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</t>
          </dd>
        </dl>
      </section>
    </section>
  </middle>
  <back>
    <references anchor="sec-normative-references">
      <name>Normative References</name>
      <reference anchor="RFC8878">
        <front>
          <title>Zstandard Compression and the 'application/zstd' Media Type</title>
          <author fullname="Y. Collet" initials="Y." surname="Collet"/>
          <author fullname="M. Kucherawy" initials="M." role="editor" surname="Kucherawy"/>
          <date month="February" year="2021"/>
          <abstract>
            <t>Zstandard, or "zstd" (pronounced "zee standard"), is a lossless data compression mechanism. This document describes the mechanism and registers a media type, content encoding, and a structured syntax suffix to be used when transporting zstd-compressed content via MIME.</t>
            <t>Despite use of the word "standard" as part of Zstandard, readers are advised that this document is not an Internet Standards Track specification; it is being published for informational purposes only.</t>
            <t>This document replaces and obsoletes RFC 8478.</t>
          </abstract>
        </front>
        <seriesInfo name="RFC" value="8878"/>
        <seriesInfo name="DOI" value="10.17487/RFC8878"/>
      </reference>
      <reference anchor="RFC2119">
        <front>
          <title>Key words for use in RFCs to Indicate Requirement Levels</title>
          <author fullname="S. Bradner" initials="S." surname="Bradner"/>
          <date month="March" year="1997"/>
          <abstract>
            <t>In many standards track documents several words are used to signify the requirements in the specification. These words are often capitalized. This document defines these words as they should be interpreted in IETF documents. This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements.</t>
          </abstract>
        </front>
        <seriesInfo name="BCP" value="14"/>
        <seriesInfo name="RFC" value="2119"/>
        <seriesInfo name="DOI" value="10.17487/RFC2119"/>
      </reference>
      <reference anchor="RFC8174">
        <front>
          <title>Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words</title>
          <author fullname="B. Leiba" initials="B." surname="Leiba"/>
          <date month="May" year="2017"/>
          <abstract>
            <t>RFC 2119 specifies common key words that may be used in protocol specifications. This document aims to reduce the ambiguity by clarifying that only UPPERCASE usage of the key words have the defined special meanings.</t>
          </abstract>
        </front>
        <seriesInfo name="BCP" value="14"/>
        <seriesInfo name="RFC" value="8174"/>
        <seriesInfo name="DOI" value="10.17487/RFC8174"/>
      </reference>
    </references>
    <?line 160?>

<section numbered="false" anchor="acknowledgments">
      <name>Acknowledgments</name>
      <t>zstd was developed by Yann Collet.</t>
      <t>The authors would like to thank Yann Collet, Klaus Post, 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. Also, thank you to Nick Terrell
for providing feedback that went into RFC 8478 and RFC 8878.</t>
    </section>
  </back>
  <!-- ##markdown-source:
H4sIAAAAAAAAA41Y7XLbuBX9j6e4lX802UpyFGcnrifdRLGdjXdjx7WU8aSd
/gBJSEJMAioAWlE8eZc+S5+s5wKUTEbONpNxJILA/Tz33AsNBgMRdCjVEfWu
tSnsiib6izZzmllH//BBmkK6go6tCcoEOjW5LfC6J2SWOXWLY9hU0P1Z1RO5
DGpu3fqItJlZIQqbG1lBReHkLAw+yU/1YBHCMtN+8AWnB6t4euBxevDkifB1
VmnvNXSulzh2djp9Q7RHsvQWCrFZLRX+M6HXp54qdLBOy5Ifzsav8QHTe2dX
0zc9YeoqU+5IFDDpSOTWeGV87Y8ouFoJmH8gpFOSvVcZwVk6g6POqEBTJ41f
Whd6YmXdzdzZeol9b6fTy9dnk564UWusF0eCBsReNJ8pYPyQ22rpVPQjPaYQ
qiaEvCaXy1IjXNiyH2XcKlPDUKIddUQpGL1rGMMJ+pV38HoldclhUWEWwzpY
zV+tDobWzfmtdPkCb/mFP9rfL7UPfphe74/xTt8qv39ZZ7Bjvy1inw/PdVjU
GY4bXSw0J24/5fDbtPHmEjH2oaVre2iY5Ay1/c7x/R9AxnARqrInhKzDwjoO
O3QSzeqyTOi6YHX0G2TEF3BQGv0lBveIfrV2Xqr4wgenFOycLHRWryVN8Cyr
Ph3Q8cJWavB0NDjYvIwHnJpHGZsDxzqs+zS1N2sb3yOfUD/6+QnA++Rps1Sb
wBXwm1xKE5dUytM2KK/m0aQhYLLry/WQ3qhSf6bLIb0FpIJ6wKdzFSRdIuyo
1cr3Ad182PHw4PAJXdPBAQp4EpJdM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