Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use of a mismatching unicode path extra field in zip unarchiving #167

Merged
merged 2 commits into from Apr 12, 2021
Merged

Fix use of a mismatching unicode path extra field in zip unarchiving #167

merged 2 commits into from Apr 12, 2021

Conversation

cwalther
Copy link
Contributor

The zip spec (§4.6.9) says that a unicode path extra field is only to be used when its CRC matches the current file name. Using it unconditionally, as introduced in a080e0a, is wrong. Commons.compress already does it right internally, there is no need to do anything in plexus-archiver.

These commits add some tests for the misbehavior using a specially crafted zip file (two variants supplied for completeness, although only one is useful for the test, see commit message) as well as a fix.

Originally the bug affected archive extraction, causing files to be extracted at wrong paths. This changed, probably unintentionally, with 2aec2ba (released in 4.2.0); since then only direct use of FileInfo has been affected, e.g. when using file selectors. The tests cover both situations.

For a real-world example where this caused problems, see https://repo1.maven.org/maven2/net/java/dev/jna/jna/5.6.0/jna-5.6.0.jar: It includes such a stale unicode path extra field for file com/sun/jna/linux-x86-64/libjnidispatch.so with contents libjnidispatch.so, meaning that plexus-archiver, unlike standards-compliant unarchivers, would extract that file in the root of the archive instead of the proper subfolder. This then caused https://download.eclipse.org/releases/2021-03/202103171000/plugins/com.sun.jna_5.6.0.v20200716-0148.jar (shipped with Eclipse 2021-03, built here) to include it in that incorrect location, rendering it inoperable on Linux x86-64.

@plamentotev plamentotev added this to the plexus-archiver-4.2.5 milestone Apr 3, 2021
@plamentotev plamentotev added the bug label Apr 3, 2021
@plamentotev
Copy link
Member

Thanks for the contribution and the detailed explanation. Would be great if if you can add README.md file together with the specially crafted files with instruction how they are crafted so they can be easily recreated.

One of them currently failing due to a bug, to be fixed in the next commit.

Two test files included, one with the EFS bit (language encoding flag) set,
the other without. Only efsclear.zip is used in tests because the zip spec
does not specify which prevails when both the bit is set and an extra field
is present - plexus-archiver and all other unarchivers I've tried ignore
the extra field in that case.
The zip spec (§4.6.9) says that a unicode path extra field is only to be
used when its CRC matches the current file name. Using it unconditionally,
as introduced in a080e0a, is wrong. Commons.compress already does it right
internally, no need to do anything here.

The bug affected extracting until 2aec2ba as a side effect replaced use of
fileInfo.getName() by ze.getName(); recently only direct use of FileInfo,
e.g. in file selectors, was affected.
@cwalther
Copy link
Contributor Author

Both done. I also added the Java code I used to generate the test files.

@plamentotev plamentotev merged commit b074384 into codehaus-plexus:master Apr 12, 2021
@plamentotev
Copy link
Member

Thanks a lot. Great work.

@cwalther
Copy link
Contributor Author

Thanks!

creckord pushed a commit to creckord/orbit-recipes that referenced this pull request Jun 17, 2021
A bug in plexus-archiver caused the built JNA plugin to have
libjnidispatch.so for linux-x86-64 in the wrong place. Update
maven-dependency-plugin to 3.1.2, which uses plexus-archiver 4.2.2,
where the bug is fixed.

See also codehaus-plexus/plexus-archiver#167

Change-Id: I8d38918c9adb72122fcc8a9c1980765e011df045
Signed-off-by: Christian Walther <walther@indel.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants