Martin Mirchev created COMPRESS-738:
---------------------------------------
Summary: SevenZFile.read() before getNextEntry() throws
ArrayIndexOutOfBoundsException instead of its ArchiveException
Key: COMPRESS-738
URL: https://issues.apache.org/jira/browse/COMPRESS-738
Project: Commons Compress
Issue Type: Bug
Reporter: Martin Mirchev
Calling {{SevenZFile.read()}} (or {{read(byte[])}}) before the first
{{getNextEntry()}} throws
{noformat}
java.lang.ArrayIndexOutOfBoundsException: Index -1 out of bounds for length 2
at
org.apache.commons.compress.archivers.sevenz.SevenZFile.getCurrentStream(SevenZFile.java:1096)
at
org.apache.commons.compress.archivers.sevenz.SevenZFile.read(SevenZFile.java:1320)
{noformat}
{{getCurrentStream()}} already has the intended error, {{ArchiveException("No
current 7z entry (call getNextEntry() first).")}}, but it first reads
{{archive.files[currentEntryIndex]}}, and {{currentEntryIndex}} is -1 until
{{getNextEntry()}} is called. The same happens for an archive with no entries.
Reproducer (any archive, for example {{src/test/resources/bla.7z}}):
{code:java}
try (SevenZFile sevenZFile = SevenZFile.builder().setFile(new
File("bla.7z")).get()) {
sevenZFile.read(); // ArrayIndexOutOfBoundsException
}
{code}
Suggested fix: throw the existing {{ArchiveException}} when
{{currentEntryIndex}} is negative. A pull request with the fix and a test
follows.
This issue was found by an LLM-Enhanced Static Analysis Engine and verified
manually.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)