From 92cf5cd898576897ec318bae3e21a330eec9318d Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Mon, 6 Feb 2023 18:12:09 +1000 Subject: [PATCH] Don't enforce download size on client https://forums.ankiweb.net/t/local-sync-server-collection-exceeds-size-limit/27183/6 --- rslib/src/sync/http_client/io_monitor.rs | 4 ++-- rslib/src/sync/request/header_and_stream.rs | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/rslib/src/sync/http_client/io_monitor.rs b/rslib/src/sync/http_client/io_monitor.rs index 6361d5c36..1ffa44d52 100644 --- a/rslib/src/sync/http_client/io_monitor.rs +++ b/rslib/src/sync/http_client/io_monitor.rs @@ -29,7 +29,7 @@ use crate::sync::error::HttpError; use crate::sync::error::HttpResult; use crate::sync::error::HttpSnafu; use crate::sync::error::OrHttpErr; -use crate::sync::request::header_and_stream::decode_zstd_body_stream; +use crate::sync::request::header_and_stream::decode_zstd_body_stream_for_client; use crate::sync::request::header_and_stream::encode_zstd_body_stream; use crate::sync::response::ORIGINAL_SIZE; @@ -131,7 +131,7 @@ impl IoMonitor { let response_stream = self.wrap_stream( false, response_total, - decode_zstd_body_stream(resp.bytes_stream()), + decode_zstd_body_stream_for_client(resp.bytes_stream()), ); let mut reader = StreamReader::new(response_stream.map_err(|e| { diff --git a/rslib/src/sync/request/header_and_stream.rs b/rslib/src/sync/request/header_and_stream.rs index c36356b25..b9da003a0 100644 --- a/rslib/src/sync/request/header_and_stream.rs +++ b/rslib/src/sync/request/header_and_stream.rs @@ -38,7 +38,7 @@ impl SyncRequest { T: DeserializeOwned, { sync_header.sync_version.ensure_supported()?; - let data = decode_zstd_body(body_stream).await?; + let data = decode_zstd_body_for_server(body_stream).await?; Ok(Self { sync_key: sync_header.sync_key, session_key: sync_header.session_key, @@ -52,7 +52,8 @@ impl SyncRequest { } } -pub async fn decode_zstd_body(data: S) -> HttpResult> +/// Enforces max payload size +pub async fn decode_zstd_body_for_server(data: S) -> HttpResult> where S: Stream> + Unpin, E: Display, @@ -70,7 +71,8 @@ where Ok(buf) } -pub fn decode_zstd_body_stream(data: S) -> impl Stream> +/// Does not enforce payload size +pub fn decode_zstd_body_stream_for_client(data: S) -> impl Stream> where S: Stream> + Unpin, E: Display, @@ -79,7 +81,7 @@ where data.map_err(|e| std::io::Error::new(ErrorKind::ConnectionAborted, format!("{e}"))), ); let reader = async_compression::tokio::bufread::ZstdDecoder::new(reader); - ReaderStream::new(reader.take(*MAXIMUM_SYNC_PAYLOAD_BYTES_UNCOMPRESSED)).map_err(|err| { + ReaderStream::new(reader).map_err(|err| { HttpSnafu { code: StatusCode::BAD_REQUEST, context: "decode zstd body",