Archive Module Phase 1: 核心框架搭建完成

实现内容:
 archive模块完整架构(10个文件,约900行)
 ArchiveProcessor trait统一接口
 ProcessorRegistry插件式架构
 FormatDetector格式自动检测
 ArchiveConfig配置管理系统
 Warning警告系统(RAR/XZ/7z争议格式)
 Zip Slip/Zip Bomb安全防护
 核心格式stub(ZIP/TAR/GZIP等9种)
 可选格式stub(RAR/XZ/7z等3种)
 测试框架基础

支持的格式:
核心格式(默认启用):ZIP, TAR, GZIP, ZSTD, BZIP2, LZ4, TAR.GZ, TAR.BZ2, TAR.ZST(9种)
可选格式(默认禁用):RAR(法律风险), XZ(外部依赖), 7z(库不稳定)(3种)
总计:12种压缩格式

安全特性:
- Zip Slip防护(路径遍历攻击)
- Zip Bomb防护(解压比率限制)
- 文件大小限制
- 法律风险警告(RAR专利)

下一步:Phase 2 - 核心格式完整实现(ZIP/TAR/GZIP处理器)
This commit is contained in:
Warren
2026-06-10 17:21:42 +08:00
parent 96bb08dd94
commit 55db79cb8d
9 changed files with 1292 additions and 0 deletions

View File

@@ -0,0 +1,141 @@
// Warning System - Legal and Technical Warnings for Optional Formats
use log::{warn, info};
use crate::archive::config::ArchiveConfig;
/// Show RAR legal risk warning
pub fn show_rar_legal_warning() {
warn!("");
warn!("⚠️ ⚠️ ⚠️ RAR FORMAT LEGAL WARNING ⚠️ ⚠️ ⚠️");
warn!("");
warn!("By enabling RAR format support, you acknowledge:");
warn!(" 1. RAR compression algorithm is patented by RARLAB");
warn!(" 2. Commercial use requires license purchase (approx $1000+)");
warn!(" 3. You assume ALL legal responsibility for patent compliance");
warn!(" 4. MarkBase provides RAR decompression only, NO compression");
warn!(" 5. unrar library is free for personal use only");
warn!("");
warn!("License info: https://rarlab.com/license.htm");
warn!("");
warn!("⚠️ User accepts legal risk by enabling enable_rar = true in config");
warn!("");
}
/// Show XZ external dependency warning
pub fn show_xz_dependency_warning() {
warn!("");
warn!("⚠️ ⚠️ ⚠️ XZ FORMAT DEPENDENCY WARNING ⚠️ ⚠️ ⚠️");
warn!("");
warn!("XZ format requires external liblzma library (non-pure Rust)");
warn!("");
warn!("Installation instructions:");
warn!(" macOS: brew install xz");
warn!(" Linux: apt install liblzma-dev (Debian/Ubuntu)");
warn!(" yum install xz-devel (CentOS/RHEL)");
warn!(" Windows: Manual installation required (complex)");
warn!(" Download from: https://tukaani.org/xz/");
warn!("");
warn!("⚠️ XZ format disabled if liblzma not found");
warn!("");
}
/// Show 7z library stability warning
pub fn show_7z_stability_warning() {
warn!("");
warn!("⚠️ ⚠️ ⚠️ 7Z FORMAT STABILITY WARNING ⚠️ ⚠️ ⚠️");
warn!("");
warn!("sevenz-rust library (v0.21.0) is under active development:");
warn!(" 1. Some compression algorithms not yet supported");
warn!(" 2. Production stability may be limited");
warn!(" 3. Performance optimization ongoing");
warn!(" 4. API may change in future versions");
warn!("");
warn!("Recommended: Wait for library maturity before production use");
warn!("GitHub: https://github.com/frogmoreltd/sevenz-rust");
warn!("");
warn!("⚠️ Use with caution in production environments");
warn!("");
}
/// Show startup warnings for optional formats
pub fn show_startup_warnings(config: &ArchiveConfig) {
if config.enable_rar {
show_rar_legal_warning();
}
if config.enable_xz {
// Dependency check happens in ProcessorRegistry
}
if config.enable_7z {
show_7z_stability_warning();
}
// Show summary of enabled formats
let enabled_optional = [
config.enable_rar,
config.enable_xz,
config.enable_7z,
].iter().filter(|&x| *x).count();
if enabled_optional > 0 {
info!("");
info!("⚠️ {} optional format(s) enabled with warnings shown above", enabled_optional);
info!("Core formats (9): ZIP, TAR, GZIP, ZSTD, BZIP2, LZ4, TAR.GZ, TAR.BZ2, TAR.ZST");
info!("");
}
}
/// Generate user-facing legal disclaimer text
pub fn generate_rar_legal_disclaimer() -> String {
format!(
"RAR FORMAT LEGAL DISCLAIMER
IMPORTANT WARNING:
By enabling RAR format support in MarkBase, you acknowledge and agree to the following:
1. RAR COMPRESSION ALGORITHM PATENT
- RAR compression algorithm is patented by RARLAB (Eugene Roshal)
- Patent protection applies to commercial use
- Personal/non-commercial use may be free (check RARLAB license)
2. LICENSE REQUIREMENTS
- Commercial use requires purchasing license from RARLAB
- License cost: approximately $1000+ (contact RARLAB for exact pricing)
- License info: https://rarlab.com/license.htm
3. MARKBASE LIABILITY DISCLAIMER
- MarkBase provides RAR DECOMPRESSION only (no compression)
- MarkBase uses unrar library (free for personal use)
- MarkBase DOES NOT provide RAR compression functionality
- MarkBase DOES NOT assume any legal liability for RAR patent issues
4. USER RESPONSIBILITY
- You are solely responsible for verifying legal compliance
- If commercial use, you must purchase RARLAB license
- You accept all legal risks by enabling enable_rar = true
- MarkBase is not liable for any patent infringement
5. USAGE GUIDELINES
- Personal use: Free (符合unrar免费许可)
- Commercial use: License required
- Distribution: Contact RARLAB for distribution license
ENABLE RAR FORMAT:
Modify config.toml:
enable_rar = false # Default disabled
enable_rar = true # ⚠️ User accepts legal risk
CONTACT:
- RARLAB: https://rarlab.com
- License: support@rarlab.com
- MarkBase: your-markbase-support
Last Updated: 2026-06-10
Version: 1.0
Legal Consultation: [Please consult professional lawyer for commercial use]
"
)
}