建议: 修复 brotli 解压缩器缓冲区拼写错误, 替换帧/头魔数
作者: Sruhvx-jpg创建于 2026年9月4日更新于 2026年9月17日
标签A-http
1. The Brotli Decompressor Buffer Typo (actix-http/src/encoding/decoder.rs) — (Resolved in #4228)
// Current code in actix-http/src/encoding/decoder.rs:
#[cfg(feature = "compress-brotli")]
ContentEncoding::Brotli => Some(ContentDecoder::Brotli(Box::new(
brotli::DecompressorWriter::new(Writer::new(), 8_096), // <-- Typo
))),- The Problem: $8,096$ is neither a power of two nor an integer multiple of the standard $4\text{ KiB}$ memory page ($8,192 - 96$). CPU cache lines and memory allocators cry themselves to sleep whenever an unaligned $8,096$-byte chunk is requested. The rest of the encoding module uses $8\text{ KiB}$ or $32\text{ KiB}$ buffers.
- The Fix: Define
const DEFAULT_DECODER_CAPACITY: usize = 8 * 1024;($8\text{ KiB}$) to restore clean page alignment (Implemented in #4228).
2. The Date Header Scratchpad Buffer (actix-http/src/config.rs)
Unit tests were already importing use crate::date::DATE_VALUE_LENGTH; (29), but the production date writer is doing manual index math:
// Current code in actix-http/src/config.rs:
let mut buf: [u8; 37] = [0; 37];
buf[..6].copy_from_slice(if camel_case { b"Date: " } else { b"date: " });
self.0.date_service.with_date(|date| buf[6..35].copy_from_slice(&date.bytes));
buf[35..].copy_from_slice(b"\r\n");- The Problem: If the date format ever shifted by even 1 byte, this function would silently slice corrupted HTTP headers or panic at runtime on an index out of bounds.
- The Fix:
const PREFIX_LEN: usize = 6; // b"Date: ".len()
const CRLF_LEN: usize = 2; // b"\r\n".len()
const DATE_HEADER_LEN: usize = PREFIX_LEN + DATE_VALUE_LENGTH +
…内容来源: actix/actix-web