Skip to content

Commit

Permalink
Changes window size max for Dictionary-Compressed Zstandard
Browse files Browse the repository at this point in the history
The spec of Compression Dictionary Transport has changed to allow larger
window size for Dictionary-Compressed Zstandard.
httpwg/http-extensions#2754
So this CL changes the window_log_max in ZstdSourceStream to follow the
spec change.

Before this CL:
  window size = max(8MB, dictionary size)

After this CL:
  window size = clamp(dictionary size * 1.25, 8MB, 128MB)

Bug: 1413922, 1479809
Change-Id: I28853afd8e61107c3d1df3a3eb3f72d99b6fa796
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5561364
Reviewed-by: Adam Rice <[email protected]>
Commit-Queue: Tsuyoshi Horo <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1304911}
  • Loading branch information
horo-t authored and Chromium LUCI CQ committed May 23, 2024
1 parent 93443c1 commit daa88b7
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions net/filter/zstd_source_stream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ class ZstdSourceStream : public FilterSourceStream {
// to '... protect decoders from unreasonable memory requirements'.
int window_log_max = 23;
if (dictionary_) {
// For shared dictionary case, allow using larger window size (Log2Ceiling
// of `dictionary_size`). It is safe because we have the size limit per
// shared dictionary and the total dictionary size limit.
window_log_max =
std::max(base::bits::Log2Ceiling(
base::checked_cast<uint32_t>(dictionary_size_)),
window_log_max);
// For shared dictionary case, allow using larger window size:
// clamp(dictionary size * 1.25, 8MB, 128MB)
// See https://github.com/httpwg/http-extensions/issues/2754 for more
// details. To avoid floating point calculations, using `* 5 / 4` for
// `* 1.25` specified by the standard.
// Note: `base::checked_cast<uint32_t>` is safe because we have the size
// limit per shared dictionary and the total dictionary size limit.
window_log_max = std::clamp(
base::bits::Log2Ceiling(
base::checked_cast<uint32_t>(dictionary_size_ * 5 / 4)),
23, // 8MB
27); // 128MB
}
ZSTD_DCtx_setParameter(dctx_.get(), ZSTD_d_windowLogMax, window_log_max);
if (dictionary_) {
Expand Down

0 comments on commit daa88b7

Please sign in to comment.