fix(lib): compress peer listings and reject a bad zlib checksum

A browse or folder listing and a search reply went out as zlib "stored"
blocks, so a big share cost every browser its full uncompressed size,
and the inflater ignored the adler32 trailer, so corrupt data passed.
Listings now deflate through a fixed-Huffman encoder over an LZ77 match
finder, which shrinks a listing's repeated path prefixes to about a
tenth, and a stream whose trailer does not match is refused. No crate:
the encoder is a hundred lines beside the inflater it feeds, and the
inflater is named for what it does.
This commit is contained in:
Michel de Graaf
2026-09-07 16:59:14 +02:00
parent ee60d47d88
commit 8329395c92
6 changed files with 305 additions and 89 deletions
@@ -8,7 +8,7 @@ use crate::message::peer::shared_file_list::{
};
use crate::message::{Message, MessageHandler};
use crate::peer::PeerMessage;
use crate::utils::zlib::compress_stored;
use crate::utils::zlib::deflate;
use std::sync::mpsc::Sender;
pub struct FolderContentsRequest;
@@ -36,7 +36,7 @@ pub fn build_folder_contents(
write_directories(&mut payload, dirs);
Message::new()
.write_int32(37)
.write_raw_bytes(compress_stored(&payload.get_data()))
.write_raw_bytes(deflate(&payload.get_data()))
.clone()
}