[ https://issues.apache.org/jira/browse/COMPRESS-497?focusedWorklogId=337716&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-337716 ]
ASF GitHub Bot logged work on COMPRESS-497: ------------------------------------------- Author: ASF GitHub Bot Created on: 02/Nov/19 16:13 Start Date: 02/Nov/19 16:13 Worklog Time Spent: 10m Work Description: bodewig commented on pull request #85: COMPRESS-497 Handle missing endheader offset URL: https://github.com/apache/commons-compress/pull/85#discussion_r341816574 ########## File path: src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java ########## @@ -441,17 +441,81 @@ private Archive readHeaders(final byte[] password) throws IOException { archiveVersionMajor, archiveVersionMinor)); } + boolean headerLooksValid = false; // See https://www.7-zip.org/recover.html - "There is no correct End Header at the end of archive" final long startHeaderCrc = 0xffffFFFFL & buf.getInt(); - final StartHeader startHeader = readStartHeader(startHeaderCrc); + if (startHeaderCrc == 0) { + // This is an indication of a corrupt header - peek the next 20 bytes + long currentPosition = channel.position(); + ByteBuffer peekBuf = ByteBuffer.allocate(20); + readFully(peekBuf); + channel.position(currentPosition); + // Header invalid if all data is 0 + while (peekBuf.hasRemaining()) { + if (peekBuf.get()!=0) { + headerLooksValid = true; + break; + } + } + } else { + headerLooksValid = true; + } + + if (headerLooksValid) { + final StartHeader startHeader = readStartHeader(startHeaderCrc); + return initializeArchive(startHeader, password, true); + } else { + // No valid header found - probably first file of multipart archive was removed too early. Scan for end header. Review comment: actually I can do this kind of cosmetic change myself, :-) ---------------------------------------------------------------- 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: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 337716) Time Spent: 40m (was: 0.5h) > Handle missing offset to end header in 7z > ----------------------------------------- > > Key: COMPRESS-497 > URL: https://issues.apache.org/jira/browse/COMPRESS-497 > Project: Commons Compress > Issue Type: Improvement > Components: Archivers > Reporter: Stefan Schlott > Priority: Major > Time Spent: 40m > Remaining Estimate: 0h > > When dealing with multipart 7z files, it may occur that the start header is > invalid (all zeros) - see [https://www.7-zip.org/recover.html], section > "There is no correct End Header at the end of archive". This can happen if > the first part of the file is moved while the overall operation hasn't > finished yet (the start header is written as very last step). > Detect a missing start header (all bytes are zero) and try to guess the end > header. -- This message was sent by Atlassian Jira (v8.3.4#803005)