Skip to content

Implement basic writer support#5

Merged
jkorany merged 1 commit intomainfrom
writer_support
Jan 6, 2026
Merged

Implement basic writer support#5
jkorany merged 1 commit intomainfrom
writer_support

Conversation

@jkorany
Copy link
Collaborator

@jkorany jkorany commented Dec 22, 2025

Implementing the minimum needed support for creating an archive via the LZMA SDK

@dryrunsecurity
Copy link

dryrunsecurity bot commented Dec 22, 2025

DryRun Security

This pull request contains a TOCTOU symlink vulnerability in CArchiveExtractCallback::GetStream (ext/lzma_sdk_wrapper/archive_callbacks.cpp lines 126–137) where a non-atomic check-delete-create sequence when handling existing files allows a local attacker with write access to the extraction directory to replace the target with a symlink and cause arbitrary file overwrite.

TOCTOU Symlink Attack during Extraction in ext/lzma_sdk_wrapper/archive_callbacks.cpp
Vulnerability TOCTOU Symlink Attack during Extraction
Description The C++ extraction implementation in CArchiveExtractCallback::GetStream uses a non-atomic sequence (Check-Delete-Create) to handle existing files, which creates a Time-of-Check to Time-of-Use (TOCTOU) race condition. A local attacker with write access to the extraction directory could exploit this window by replacing the target file with a symbolic link pointing to an arbitrary location on the filesystem, leading to an arbitrary file overwrite.

NFind::CFileInfo fi;
if (fi.Find(fullPath))
{
if (!NDir::DeleteFileAlways(fullPath))
{
return E_FAIL;
}
}
}
if (!_outFileStreamSpec->Create_ALWAYS(fullPath))
{


All finding details can be found in the DryRun Security Dashboard.

Features:
- Archive Writer class for creating 7z archives
- Support for adding files, directories, and in-memory data
- Password encryption support
- Configurable compression options (method, level, solid mode)

Security:
- Zip Slip prevention in Writer (path sanitization)
- Archive bomb protection in Reader (size/ratio limits)
- Configurable extraction limits:
  - max_entry_size (default: 1GB)
  - max_total_size (default: 10GB)
  - max_compression_ratio (default: 1000:1)
  - max_size_for_unknown_ratio (default: 10MB)
- Path traversal protection during extraction

Tests:
- Comprehensive Writer specs
- Security tests for both Reader and Writer
- Docker-verified archive bomb protection
Copy link
Contributor

@krippee krippee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jkorany jkorany merged commit 64b1e53 into main Jan 6, 2026
9 checks passed
@jkorany jkorany deleted the writer_support branch January 22, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments