You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "garydgregory (via GitHub)" <gi...@apache.org> on 2025/12/05 19:09:04 UTC
[PR] [COMPRESS-714] Internal IllegalArgumentException in ZipFile and TarFile creation is not caught [commons-compress]
garydgregory opened a new pull request, #754:
URL: https://github.com/apache/commons-compress/pull/754
Fixes Jira https://issues.apache.org/jira/browse/COMPRESS-714
Before you push a pull request, review this list:
- [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
- [x] Read the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) if you use Artificial Intelligence (AI).
- [ ] I used AI to create any part of, or all of, this pull request.
- [x] Run a successful build using the default [Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command line by itself.
- [x] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice.
- [x] Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
- [x] Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process.
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [COMPRESS-714] Internal IllegalArgumentException in ZipFile and TarFile creation is not caught [commons-compress]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #754:
URL: https://github.com/apache/commons-compress/pull/754#issuecomment-3941083872
@aisle-analyzer experiment.
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [COMPRESS-714] Internal IllegalArgumentException in ZipFile and TarFile creation is not caught [commons-compress]
Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on code in PR #754:
URL: https://github.com/apache/commons-compress/pull/754#discussion_r2614005312
##########
src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java:
##########
@@ -756,12 +756,8 @@ private ZipFile(final Builder builder) throws IOException {
}
fillNameMap();
} catch (final IOException e) {
- final ArchiveException archiveException = e instanceof ArchiveException
- ? (ArchiveException) e
- : new ArchiveException("Error reading Zip content from " + builder.getName(), (Throwable) e);
this.closed = true;
- IOUtils.close(archive, archiveException::addSuppressed);
- throw archiveException;
+ throw IOUtils.closeQuietly(archive, e);
}
Review Comment:
Same as above: I wouldn't rely on an unpublished IO method and use what is available now.
```java
} catch (final Exception e) {
this.closed = true;
final IOException ioe = e instanceof IOException ? (IOException) e : new ArchiveException(e);
IOUtils.closeQuietly(archive, ioe::addSuppressed);
throw ioe;
}
```
##########
src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java:
##########
@@ -629,9 +629,7 @@ private SevenZFile(final Builder builder) throws IOException {
archive = readHeaders(password);
this.password = password != null ? Arrays.copyOf(password, password.length) : null;
} catch (final ArithmeticException | IllegalArgumentException e) {
- final ArchiveException archiveException = new ArchiveException(e);
- IOUtils.close(channel, archiveException::addSuppressed);
- throw archiveException;
+ throw IOUtils.closeQuietly(channel, new ArchiveException(e));
}
Review Comment:
Honestly, I wouldn't delay the release of `commons-compress` version `1.29.0` more than it already has been to wait for a new version of `commons-io`.
Let's use what we have in `2.21.0`:
```java
} catch (final Exception e) {
final IOException ioe = e instanceof IOException ? (IOException) e : new ArchiveException(e);
IOUtils.closeQuietly(channel, ioe::addSuppressed);
throw ioe;
}
```
When we **do** release Commons IO version `2.22.0`, we'll update this call site and **all** the other call sites that might benefit from the new method. There is no chance to forget that, since `closeQuietly` becomes ambiguous in IO `2.22.0`.
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [COMPRESS-714] Internal IllegalArgumentException in ZipFile and TarFile creation is not caught [commons-compress]
Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on code in PR #754:
URL: https://github.com/apache/commons-compress/pull/754#discussion_r2596376658
##########
src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java:
##########
@@ -191,13 +191,16 @@ private TarFile(final Builder builder) throws IOException {
while ((entry = getNextTarEntry()) != null) {
entries.add(entry);
}
- } catch (final IOException ex) {
+ } catch (final IOException | IllegalArgumentException e) {
Review Comment:
I’m wondering whether extending the catch clause from `IOException` to `IOException | IllegalArgumentException` is the right boundary. If the intention is to shield users from **any** unexpected internal failures we should rather catch `Exception`.
However, I see unchecked exceptions here as symptoms of underlying bugs. Masking them in the constructor can improve user experience, but only hides the bugs, instead of solving them.
In the specific case of COMPRESS-714, the `IllegalArgumentException` comes from a bug in `SeekableInMemoryByteChannel`. According to the `position()` contract, providing a position larger than the channel size should not result in an exception, so the current implementation violates that contract:
https://github.com/apache/commons-compress/blob/b83da24c57ec32cf4c4ee7dcb58b09861c9c17ce/src/main/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannel.java#L114-L121
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [COMPRESS-714] Internal IllegalArgumentException in ZipFile and TarFile creation is not caught [commons-compress]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory merged PR #754:
URL: https://github.com/apache/commons-compress/pull/754
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [COMPRESS-714] Internal IllegalArgumentException in ZipFile and TarFile creation is not caught [commons-compress]
Posted by "jtattermusch (via GitHub)" <gi...@apache.org>.
jtattermusch commented on PR #754:
URL: https://github.com/apache/commons-compress/pull/754#issuecomment-3941014727
> @@aisle-analyzer experiment.
it's supposed to be @aisle-analyzer, can you please try again?
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [COMPRESS-714] Internal IllegalArgumentException in ZipFile and TarFile creation is not caught [commons-compress]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #754:
URL: https://github.com/apache/commons-compress/pull/754#issuecomment-3940886639
@aisle-research experiment.
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [COMPRESS-714] Internal IllegalArgumentException in ZipFile and TarFile creation is not caught [commons-compress]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #754:
URL: https://github.com/apache/commons-compress/pull/754#discussion_r2596392357
##########
src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java:
##########
@@ -191,13 +191,16 @@ private TarFile(final Builder builder) throws IOException {
while ((entry = getNextTarEntry()) != null) {
entries.add(entry);
}
- } catch (final IOException ex) {
+ } catch (final IOException | IllegalArgumentException e) {
Review Comment:
Hm good catch, here's a fix: https://github.com/apache/commons-compress/pull/756 (now merged).
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [COMPRESS-714] Internal IllegalArgumentException in ZipFile and TarFile creation is not caught [commons-compress]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on code in PR #754:
URL: https://github.com/apache/commons-compress/pull/754#discussion_r2596392357
##########
src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java:
##########
@@ -191,13 +191,16 @@ private TarFile(final Builder builder) throws IOException {
while ((entry = getNextTarEntry()) != null) {
entries.add(entry);
}
- } catch (final IOException ex) {
+ } catch (final IOException | IllegalArgumentException e) {
Review Comment:
Hm good catch, here's a fix https://github.com/apache/commons-compress/pull/756
##########
src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java:
##########
@@ -191,13 +191,16 @@ private TarFile(final Builder builder) throws IOException {
while ((entry = getNextTarEntry()) != null) {
entries.add(entry);
}
- } catch (final IOException ex) {
+ } catch (final IOException | IllegalArgumentException e) {
Review Comment:
Hm good catch, here's a fix: https://github.com/apache/commons-compress/pull/756
--
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.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org