zip: preserve legacy Zstandard method 20 in lenient reads (#2015)

* zip: retain legacy Zstandard method compatibility

Ported from Craft Anything 29badae7c9280fdf4c24795927bf3a91f51694c6, including the bounded-reader regression. Firmware scanner policy remains app-owned.

* Record source of legacy ZIP Zstandard compatibility

* Document both ZIP Zstandard method identifiers

---------

Co-authored-by: RRFZ <247457381+Plastic-time@users.noreply.github.com>
This commit is contained in:
Dylan M. TaylorandRRFZ authored and GitHub committed 2026-11-17 14:14:21 -05:00
1 parent 5039e49ab6
commit fb1d7f3681
4 files changed
+42 -3

No files matched your search

+2
View File
@@ -119,6 +119,7 @@ The XML reader in `crates/plist/src/xml.rs` and its base64 compatibility helper
`crates/palette` extracts the GPL text parser from AniCraft `crates/doc/src/swatch.rs` at `d875a7feb250e6ab06aa28a37fb78a0699e88330` (MIT OR Apache-2.0), introduced by Tanish Manku in `a64130a9da9bdde545463b852d95d6a6774b1dfd` (AniCraft #270). The import preserves Tanish as primary author. Neutral RGB/name adaptation separates application display-name sanitization and the `Untitled` policy; validation tests and integration are subsequent Dylan M. Taylor changes.
The legacy ZIP Zstandard method-20 mapping and bounded-read regression in `crates/zip/src/lenient` are ported from RRFZ's Craft Anything commit `29badae7c9280fdf4c24795927bf3a91f51694c6` (MIT OR Apache-2.0). RRFZ remains the primary Git author. Firmware scanner detection remains app-owned and is not part of this port.
## TAR/CPIO compatibility updates
The old GNU sparse-extension traversal, GNU CRC-symlink compatibility and PAX-size precedence fixes and their regression tests in `crates/tar` are ported from RRFZ's Craft Anything PRs #1973 (`8ea2ec66a1bc80f0420f3695baac877a0cb9b9a5`), #1984 (`b226a475f7dce9710e3af7a069386fe7a9720df7`) and #2007 (`d29465c20b0d570ea4973be512a0cb4e212bb60f`). Source is MIT OR Apache-2.0; RRFZ remains the primary Git author of each port. The PAX update adapts to the shared parser's existing `PaxOverrides` structure without changing the source policy.
@@ -130,6 +131,7 @@ The USDZ alignment requirement and compatibility fixture for `Writer::add_stored
The raw gradient wire ordering in `craft-lottie::Gradient::flat_values` follows
AniCraft's Lottie exporter by Tanish Manku (`63b39355`, `b9258b7b`), MIT OR Apache-2.0.
Sanitization, animation fitting and numeric output policy remain caller-owned.
## Screen Video key frames
`crates/video/src/screen_video.rs` extracts AniCraft `crates/xfl/src/video.rs` codec-3 decoding and its synthetic partial-block fixture, introduced by Tanish Manku in `1f3e603b7ff53a3da364e41ec4da8d43dc83aab0` with pixel-loop cleanup `2b7571363b4b647266df758f95b6e397021cfd4d` (MIT OR Apache-2.0). Import commits preserve Tanish as primary author. Caller-owned bounds and neutral RGBA output separate codec work from the consuming app's FLV first-frame/report policy. Boundary tests and integration are subsequent Dylan M. Taylor changes.
+1 -1
View File
@@ -35,7 +35,7 @@ lenient = ["dep:miniz_oxide"]
lenient-bzip2 = ["lenient", "dep:bzip2-rs"]
# Methods 14 (ZIP LZMA) and 95 (XZ).
lenient-lzma = ["lenient", "dep:lzma-rs"]
# Method 93.
# Zstandard methods 20 (legacy) and 93.
lenient-zstd = ["lenient", "dep:ruzstd"]
serde = ["dep:serde"]
+2 -2
View File
@@ -91,7 +91,7 @@ impl ZipEntry {
9 => "deflate64",
12 => "bzip2",
14 => "lzma",
93 => "zstd",
20 | 93 => "zstd",
95 => "xz",
99 => "aes",
_ => "other",
@@ -463,7 +463,7 @@ pub fn read_entry_unverified(data: &[u8], e: &ZipEntry, max_bytes: u64) -> Resul
})?,
12 | 95 => decode_bzip2_or_xz(raw, e, max_bytes)?,
14 => decode_lzma(raw, e, max_bytes)?,
93 => decode_zstd(raw, e, max_bytes)?,
20 | 93 => decode_zstd(raw, e, max_bytes)?,
m => return Err(ZipError::Unsupported(format!("compression method {m} ({}) for {}", e.method_name(), e.name))),
};
if out.len() as u64 != e.uncompressed_size {
+37
View File
@@ -391,3 +391,40 @@ fn a_method_left_out_of_the_build_is_unsupported() {
data[8..10].copy_from_slice(&93u16.to_le_bytes());
assert!(matches!(read_entry_unverified(&data, &entry, 100), Err(ZipError::Unsupported(m)) if m.contains("not built in")));
}
// RRFZ, Craft Anything 29badae7: deprecated ZIP method 20 is Zstandard.
#[cfg(feature = "lenient-zstd")]
mod legacy_zstandard {
use crate::lenient as zip;
use crate::lenient::testkit::zip_stored;
const BODY: &[u8] = b"zstandard payload";
/// Build a ZIP with one single-segment Zstandard frame containing a raw final block.
fn sample(method: u16) -> Vec<u8> {
let size = BODY.len() as u8;
let mut frame = vec![0x28, 0xb5, 0x2f, 0xfd, 0x20, size, (size << 3) | 1, 0, 0];
frame.extend_from_slice(BODY);
let mut data = zip_stored(&[("a.txt", &frame)]);
let cd = 30 + "a.txt".len() + frame.len();
data[8..10].copy_from_slice(&method.to_le_bytes());
data[14..18].copy_from_slice(&zip::crc32(BODY).to_le_bytes());
data[22..26].copy_from_slice(&u32::from(size).to_le_bytes());
data[cd + 10..cd + 12].copy_from_slice(&method.to_le_bytes());
data[cd + 16..cd + 20].copy_from_slice(&zip::crc32(BODY).to_le_bytes());
data[cd + 24..cd + 28].copy_from_slice(&u32::from(size).to_le_bytes());
data
}
/// The deprecated and current method IDs both decode through the bounded ZIP reader.
#[test]
fn reads_zstandard_members_under_both_method_ids() {
for method in [93, 20] {
let data = sample(method);
let entry = zip::parse(&data, 1).unwrap().entries.remove(0);
assert_eq!(entry.method_name(), "zstd", "method {method}");
assert_eq!(zip::read_entry(&data, &entry, 100).unwrap(), BODY);
assert!(matches!(zip::read_entry(&data, &entry, 2), Err(zip::ZipError::TooLarge(2))));
}
}
}