Java_Java10commonscompress
Java_Java10commonscompress
{
"id": 10,
"repo_name": "commons-compress",
"Commit URL":
"https://github.com/apache/commons-compress/commit/347660646cfad588481c13058842d49f
a3779f84?diff=split",
"Issue URL": "https://issues.apache.org/jira/browse/COMPRESS-164",
"language": "Java"
}
====================Info End====================================
While extracting for desired refinement code please be careful in choosing the
right line of code.
ZipFile doesn't work properly for unicode extra fields. Based on patc… …h by
Volker Leidl. COMPRESS-164git-svn-id:
https://svn.apache.org/repos/asf/commons/proper/compress/trunk@1210501 13f79535-
47bb-0310-9956-ffa450edef68
{
"Do you want to reject this annotation": {
"options": [
"1. Yes",
"2. No"
],
"answer": "2"
},
"Does the code have a valid bug": {
"options": [
"1. Yes",
"2. No"
],
"answer": "1"
},
"Is the provided refinement correct": {
"options": [
"1. Correct",
"2. Not Correct",
"3. Partially Correct"
],
"answer": "1"
},
The `ZipFile` class is used to read entries from a zip file. The purpose of this
code is to store the entries in a `HashMap`. But, after initially populating the
`HashMap`, the Unicode extra fields are being read, causing the alteration in the
`ZipArchiveEntry` name and its hash code, because of which the subsequent `HashMap`
calls fail to retrieve the original values. This causes the
`ZipFile.getInputStream()` to return null for a zip file created with WinZip
containing Unicode extra fields.
To enable the reading of zip files with Unicode extra fields, a new `LinkedHashMap`
is created with the key of type `ZipArchiveEntry`, and the values of type
`OffsetEntry` to store a copy of the original `entries` map. It then clears the
original `entries` map before iterating over the keys of `origMap`. By using a
`for-each` loop, the `OffsetEntry` values corresponding to each key in the
`LinkedHashMap` are retrieved. The code subsequently adds a key-value pair to the
`entries` map, where the key is a `ZipArchiveEntry` object and the value is an
`OffsetEntry` object. This will maintain the association between ZIP entries and
their offsets within the archive and ensure that the iteration order remains
consistent by reconstructing the entries `HashMap` after the Unicode extra fields
have been parsed. After making these changes in the code, the Unicode extra fields
in zip files will be properly handled.
src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
```
@@ -805,11 +805,8 @@ public class ZipFile {
// the hashcode - see COMPRESS-164
// Map needs to be reconstructed in order to keep central
// directory order
Map<ZipArchiveEntry, OffsetEntry> origMap =
new LinkedHashMap<ZipArchiveEntry, OffsetEntry>(entries);
entries.clear();
for (ZipArchiveEntry ze : origMap.keySet()) {
OffsetEntry offsetEntry = origMap.get(ze);
long offset = offsetEntry.headerOffset;
archive.seek(offset + LFH_OFFSET_FOR_FILENAME_LENGTH);
byte[] b = new byte[SHORT];
@@ -842,7 +839,6 @@ public class ZipFile {
nameMap.put(ze.getName(), ze);
}
}
entries.put(ze, offsetEntry);
}
}
```
===================Desired Refinement Code End ====================================