[
https://issues.apache.org/jira/browse/COMPRESS-542?focusedWorklogId=469187&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-469187
]
ASF GitHub Bot logged work on COMPRESS-542:
-------------------------------------------
Author: ASF GitHub Bot
Created on: 11/Aug/20 12:15
Start Date: 11/Aug/20 12:15
Worklog Time Spent: 10m
Work Description: PeterAlfredLee commented on a change in pull request
#120:
URL: https://github.com/apache/commons-compress/pull/120#discussion_r468531249
##########
File path:
src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
##########
@@ -997,6 +1000,9 @@ private void readFilesInfo(final ByteBuffer header, final
Archive archive) throw
throw new IOException("Unimplemented");
}
for (int i = 0; i < files.length; i++) {
+ if (files[i] == null) {
+ files[i] = new SevenZArchiveEntry();
+ }
Review comment:
Agree with @garydgregory about this duplicate code. We can have a simple
refactor here.
##########
File path:
src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
##########
@@ -1090,7 +1108,13 @@ private void readFilesInfo(final ByteBuffer header,
final Archive archive) throw
++emptyFileCounter;
}
}
- archive.files = files;
+ List<SevenZArchiveEntry> entries = new ArrayList<>();
Review comment:
Maybe a final here?
```
final List<SevenZArchiveEntry> entries = new ArrayList<>();
```
##########
File path:
src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
##########
@@ -981,8 +979,13 @@ private void readFilesInfo(final ByteBuffer header, final
Archive archive) throw
int nextName = 0;
for (int i = 0; i < names.length; i += 2) {
if (names[i] == 0 && names[i+1] == 0) {
- files[nextFile++].setName(new String(names,
nextName, i-nextName, StandardCharsets.UTF_16LE));
+ String fName = new String(names, nextName, i -
nextName, StandardCharsets.UTF_16LE);
+ if (files[nextFile] == null) {
+ files[nextFile] = new SevenZArchiveEntry();
+ }
+ files[nextFile].setName(fName);
Review comment:
I think we do not need a variable `fName` here :
```
if (files[nextFile] == null) {
files[nextFile] = new SevenZArchiveEntry();
}
files[nextFile].setName(new String(names, nextName, i - nextName,
StandardCharsets.UTF_16LE));
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 469187)
Time Spent: 2h (was: 1h 50m)
> Corrupt 7z allocates huge amount of SevenZEntries
> -------------------------------------------------
>
> Key: COMPRESS-542
> URL: https://issues.apache.org/jira/browse/COMPRESS-542
> Project: Commons Compress
> Issue Type: Bug
> Affects Versions: 1.20
> Reporter: Robin Schimpf
> Priority: Major
> Attachments:
> Reduced_memory_allocation_for_corrupted_7z_archives.patch,
> endheadercorrupted.7z, endheadercorrupted2.7z
>
> Time Spent: 2h
> Remaining Estimate: 0h
>
> We ran into a problem where a 1.43GB corrupt 7z file tried to allocate about
> 138 million SevenZArchiveEntries which will use about 12GB of memory. Sadly
> I'm unable to share the file. If you have enough Memory available the
> following exception is thrown.
> {code:java}
> java.io.IOException: Start header corrupt and unable to guess end Header
> at
> org.apache.commons.compress.archivers.sevenz.SevenZFile.tryToLocateEndHeader(SevenZFile.java:511)
> at
> org.apache.commons.compress.archivers.sevenz.SevenZFile.readHeaders(SevenZFile.java:470)
> at
> org.apache.commons.compress.archivers.sevenz.SevenZFile.<init>(SevenZFile.java:336)
> at
> org.apache.commons.compress.archivers.sevenz.SevenZFile.<init>(SevenZFile.java:128)
> at
> org.apache.commons.compress.archivers.sevenz.SevenZFile.<init>(SevenZFile.java:369)
> {code}
> 7z itself aborts really quick when I'm trying to list the content of the file.
> {code:java}
> 7z l "corrupt.7z"
> 7-Zip 18.01 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2018-01-28
> Scanning the drive for archives:
> 1 file, 1537752212 bytes (1467 MiB)
> Listing archive: corrupt.7z
> ERROR: corrupt.7z : corrupt.7z
> Open ERROR: Can not open the file as [7z] archive
> ERRORS:
> Is not archive
> Errors: 1
> {code}
> I hacked together the attached patch which will reduce the memory allocation
> to about 1GB. So lazy instantiation of the entries could be a good solution
> to the problem. Optimal would be to only create the entries if the headers
> could be parsed correctly.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)