wilx opened a new pull request, #814: URL: https://github.com/apache/commons-compress/pull/814
ZIP hardlink references using the PKWARE UNIX convention currently extract as empty files. This change lets seekable `Expander` extraction restore multiple archive paths to the same filesystem inode, including forward references, chains, empty files, and cross-directory links. `ZipArchiveEntry.isUnixHardLink()` recognizes the UNIX regular-file marker in the central directory's external attributes. `ZipFile.getUnixHardLink()` decodes the target in extra field `0x000d`, `resolveUnixHardLink()` finds its terminal member, and `resolveUnixHardLinks()` resolves all chains with a cache local to that call. Terminal targets are saved while backtracking so extraction avoids quadratic chain traversal. `ZipFile.Builder.setResolveUnixHardLinks(true)` opts content streams into target resolution while preserving stored entry metadata and raw copying. Historical FAT-host archives require the separate `setAllowLegacyUnixHardLinks(true)` compatibility option. Both options default to false; seekable `Expander` automatically restores recognized hardlinks without requiring resolved content streams. Target decoding rejects malformed or unmappable bytes rather than substituting another pathname. Extraction validates targets and destination paths, writes payloads before links, and rejects missing, ambiguous, cyclic, or non-regular targets, escaping paths, symlink traversal, and destination collisions. Existing regular destinations are unlinked without truncating unrelated hardlinked files. Link creation failures propagate without a copy fallback. Streaming extraction, symlink/device restoration, and automatic writer detection are outside this change. Validation: - Default Maven goal with `JAVA_HOME=/opt/jdks/latest-17 /opt/maven/latest/bin/mvn`: 4,821 tests, zero failures/errors, 26 skipped; includes the configured coverage, licensing, Checkstyle, PMD, binary compatibility, and Javadoc checks. - All 40 hardlink tests also passed on Java 8. - The initial extraction regression failed before implementation. The chain-work and malformed UTF-8 regressions also failed against the earlier implementation and pass with these fixes. - Tests cover inode identity, independent files with identical contents, both entry orders, flag/host controls, strict charset decoding, mutation between resolution calls, raw metadata preservation, and pinned historical mount-zip fixtures. Fixture source URLs and SHA-256 values are recorded in `src/test/resources/zip-hardlinks/README.txt`. - A local 16,000-link null-output extraction probe improved from 22.84 seconds to 0.016 seconds; the regression test bounds decoding calls instead of relying on wall-clock timing. Before you push a pull request, review this list: - [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project. - [x] Read the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) if you use Artificial Intelligence (AI). - [x] I used AI to create any part of, or all of, this pull request. OpenAI Codex was used throughout source investigation, implementation, regression tests, documentation, and PR preparation, with requirements and review feedback supplied by the contributor. - [x] Run a successful build using the default [Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command line by itself. - [x] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice. - [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. - [x] Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
