From 8599909be55abb170ef10f287e585ec3a674fcdd Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 6 Oct 2024 21:14:54 +0000 Subject: [PATCH 1/6] Add failing test --- tests/decompress_chunk.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/decompress_chunk.rs diff --git a/tests/decompress_chunk.rs b/tests/decompress_chunk.rs new file mode 100644 index 00000000..0d8578f3 --- /dev/null +++ b/tests/decompress_chunk.rs @@ -0,0 +1,28 @@ +#[test] +fn deflate_decoder_partial() { + // Decompresses to + // "* QUOTAROOT INBOX \"User quota\"\r\n* QUOTA \"User quota\" (STORAGE 76 307200)\r\nA0001 OK Getquotaroot completed (0.001 + 0.000 secs).\r\n" + let input = vec![ + 210, 82, 8, 12, 245, 15, 113, 12, 242, 247, 15, 81, 240, 244, 115, 242, 143, 80, 80, 10, + 45, 78, 45, 82, 40, 44, 205, 47, 73, 84, 226, 229, 210, 130, 200, 163, 136, 42, 104, 4, + 135, 248, 7, 57, 186, 187, 42, 152, 155, 41, 24, 27, 152, 27, 25, 24, 104, 242, 114, 57, + 26, 24, 24, 24, 42, 248, 123, 43, 184, 167, 150, 128, 213, 21, 229, 231, 151, 40, 36, 231, + 231, 22, 228, 164, 150, 164, 166, 40, 104, 24, 232, 129, 20, 104, 43, 128, 104, 3, 133, + 226, 212, 228, 98, 77, 61, 94, 46, 0, 0, 0, 0, 255, 255, + ]; + + // Create very small output buffer. + let mut output = vec![0; 8]; + + let zlib_header = false; + let mut decompress = flate2::Decompress::new(zlib_header); + + let flush_decompress = flate2::FlushDecompress::None; + let status = decompress + .decompress(&input, &mut output, flush_decompress) + .unwrap(); + assert_eq!(status, flate2::Status::Ok); + + // Should not consume everything, there is not enough space in the buffer for the output. + assert_ne!(decompress.total_in(), input.len() as u64); +} From 8769362f171efb6bc8019a144f4bb8dba9346a0d Mon Sep 17 00:00:00 2001 From: link2xt Date: Mon, 7 Oct 2024 16:37:36 +0000 Subject: [PATCH 2/6] Reorder test without zlib to the end --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e3fc98a4..7c74e60c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,7 +34,6 @@ jobs: shell: bash - run: cargo build - run: rustdoc --test README.md -L target/debug/deps --extern flate2=target/debug/libflate2.rlib --edition=2018 - - run: cargo test - run: cargo test --features zlib - run: cargo test --features zlib --no-default-features - run: cargo test --features zlib-default --no-default-features @@ -46,6 +45,7 @@ jobs: if: matrix.build != 'mingw' - run: cargo test --features cloudflare_zlib --no-default-features if: matrix.build != 'mingw' + - run: cargo test - run: | if ! cargo check --no-default-features 2>&1 | grep "You need to choose"; then echo "expected message stating a zlib backend must be chosen" From 57425a68a3347d874defea60529d1b397a22618a Mon Sep 17 00:00:00 2001 From: link2xt Date: Tue, 8 Oct 2024 18:18:55 +0000 Subject: [PATCH 3/6] Make partial decompression test work with both zlib and miniz_oxide --- tests/decompress_chunk.rs | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/tests/decompress_chunk.rs b/tests/decompress_chunk.rs index 0d8578f3..520c29df 100644 --- a/tests/decompress_chunk.rs +++ b/tests/decompress_chunk.rs @@ -1,7 +1,5 @@ #[test] fn deflate_decoder_partial() { - // Decompresses to - // "* QUOTAROOT INBOX \"User quota\"\r\n* QUOTA \"User quota\" (STORAGE 76 307200)\r\nA0001 OK Getquotaroot completed (0.001 + 0.000 secs).\r\n" let input = vec![ 210, 82, 8, 12, 245, 15, 113, 12, 242, 247, 15, 81, 240, 244, 115, 242, 143, 80, 80, 10, 45, 78, 45, 82, 40, 44, 205, 47, 73, 84, 226, 229, 210, 130, 200, 163, 136, 42, 104, 4, @@ -10,19 +8,32 @@ fn deflate_decoder_partial() { 231, 22, 228, 164, 150, 164, 166, 40, 104, 24, 232, 129, 20, 104, 43, 128, 104, 3, 133, 226, 212, 228, 98, 77, 61, 94, 46, 0, 0, 0, 0, 255, 255, ]; + let expected_output = b"* QUOTAROOT INBOX \"User quota\"\r\n* QUOTA \"User quota\" (STORAGE 76 307200)\r\nA0001 OK Getquotaroot completed (0.001 + 0.000 secs).\r\n"; // Create very small output buffer. - let mut output = vec![0; 8]; + let mut output_buf = [0; 8]; + let mut output: Vec = Vec::new(); let zlib_header = false; let mut decompress = flate2::Decompress::new(zlib_header); let flush_decompress = flate2::FlushDecompress::None; - let status = decompress - .decompress(&input, &mut output, flush_decompress) - .unwrap(); - assert_eq!(status, flate2::Status::Ok); + loop { + let prev_out = decompress.total_out(); + let status = decompress + .decompress(&input[decompress.total_in() as usize..], &mut output_buf, flush_decompress) + .unwrap(); + let output_len = decompress.total_out() - prev_out; + output.extend_from_slice(&output_buf[..output_len as usize]); + eprintln!("{}", output.len()); - // Should not consume everything, there is not enough space in the buffer for the output. - assert_ne!(decompress.total_in(), input.len() as u64); + // IMAP stream never ends. + assert_ne!(status, flate2::Status::StreamEnd); + + if status == flate2::Status::BufError && output_len == 0 { + break; + } + } + + assert_eq!(output.as_slice(), expected_output); } From 40790edc9829b289a5fd574046ac5a1a56621778 Mon Sep 17 00:00:00 2001 From: link2xt Date: Tue, 8 Oct 2024 18:19:04 +0000 Subject: [PATCH 4/6] Revert "Reorder test without zlib to the end" This reverts commit 8769362f171efb6bc8019a144f4bb8dba9346a0d. --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7c74e60c..e3fc98a4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,6 +34,7 @@ jobs: shell: bash - run: cargo build - run: rustdoc --test README.md -L target/debug/deps --extern flate2=target/debug/libflate2.rlib --edition=2018 + - run: cargo test - run: cargo test --features zlib - run: cargo test --features zlib --no-default-features - run: cargo test --features zlib-default --no-default-features @@ -45,7 +46,6 @@ jobs: if: matrix.build != 'mingw' - run: cargo test --features cloudflare_zlib --no-default-features if: matrix.build != 'mingw' - - run: cargo test - run: | if ! cargo check --no-default-features 2>&1 | grep "You need to choose"; then echo "expected message stating a zlib backend must be chosen" From 1325bb3722c1c8e50355c4faa1986289880b4bb6 Mon Sep 17 00:00:00 2001 From: link2xt Date: Tue, 8 Oct 2024 18:19:48 +0000 Subject: [PATCH 5/6] Remove eprintln --- tests/decompress_chunk.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/decompress_chunk.rs b/tests/decompress_chunk.rs index 520c29df..62c01188 100644 --- a/tests/decompress_chunk.rs +++ b/tests/decompress_chunk.rs @@ -25,7 +25,6 @@ fn deflate_decoder_partial() { .unwrap(); let output_len = decompress.total_out() - prev_out; output.extend_from_slice(&output_buf[..output_len as usize]); - eprintln!("{}", output.len()); // IMAP stream never ends. assert_ne!(status, flate2::Status::StreamEnd); From 8e72245d358f4a8b2846a5abdf9ea7e8ebe1e282 Mon Sep 17 00:00:00 2001 From: link2xt Date: Tue, 8 Oct 2024 18:22:41 +0000 Subject: [PATCH 6/6] rustfmt --- tests/decompress_chunk.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/decompress_chunk.rs b/tests/decompress_chunk.rs index 62c01188..1b0809a6 100644 --- a/tests/decompress_chunk.rs +++ b/tests/decompress_chunk.rs @@ -21,7 +21,11 @@ fn deflate_decoder_partial() { loop { let prev_out = decompress.total_out(); let status = decompress - .decompress(&input[decompress.total_in() as usize..], &mut output_buf, flush_decompress) + .decompress( + &input[decompress.total_in() as usize..], + &mut output_buf, + flush_decompress, + ) .unwrap(); let output_len = decompress.total_out() - prev_out; output.extend_from_slice(&output_buf[..output_len as usize]);