You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "赵钰玮 (Jira)" <ji...@apache.org> on 2025/09/16 16:10:00 UTC
[jira] [Comment Edited] (COMPRESS-708) ZstdCompressorInputStream has a bug where the InputStream held by ZipArchiveInputStream gets closed during garbage collection (GC)
[ https://issues.apache.org/jira/browse/COMPRESS-708?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18020711#comment-18020711 ]
赵钰玮 edited comment on COMPRESS-708 at 9/16/25 4:09 PM:
-------------------------------------------------------
*Hello [~ggregory]*
*This is the corresponding Pull Request.*
[GitHub Pull Request #703|https://github.com/apache/commons-compress/pull/703]
was (Author: JIRAUSER310876):
*This is the corresponding Pull Request.*
[GitHub Pull Request #703|https://github.com/apache/commons-compress/pull/703]
[~ggregory]
> ZstdCompressorInputStream has a bug where the InputStream held by ZipArchiveInputStream gets closed during garbage collection (GC)
> ----------------------------------------------------------------------------------------------------------------------------------
>
> Key: COMPRESS-708
> URL: https://issues.apache.org/jira/browse/COMPRESS-708
> Project: Commons Compress
> Issue Type: Bug
> Reporter: 赵钰玮
> Priority: Major
> Attachments: image-2025-09-03-22-46-38-243.png
>
>
> {code:java}
> @Test
> void testZstdInputStreamErrorCloseWhenGc() throws Exception {
> final File archive = getFile("COMPRESS-692/compress-692.zip");
> for (int i =0; i< 50;i++) {
> try (FileInputStream fileInputStream = new FileInputStream(archive);
> ZipArchiveInputStream zipArchiveInputStream = new ZipArchiveInputStream(fileInputStream)){
> ArchiveEntry entry;
> while ((entry = zipArchiveInputStream.getNextEntry()) != null) {
> if (entry.isDirectory()) {
> continue;
> }
> System.gc();
> IOUtils.toByteArray(zipArchiveInputStream);
> }
> } catch (IOException e) {
> fail("testZstdInputStreamErrorCloseWhenGc error, test error at batch " + (i+1), e);
> }
> }
> } {code}
> Here is the test method. Without the line {{{}System.gc();{}}}, it may take multiple execution rounds to trigger the bug, but with this line added, the bug is almost immediately triggered. Below is the error stack log.
> !image-2025-09-03-22-46-38-243.png!
> I found that this is caused by the following: The bug occurred because the ZstdInputStream used in ZstdCompressorInputStream would close the underlying InputStream during GC, which in turn caused errors like "stream closed" for other wrapper streams (such as ZipArchiveInputStream) that depend on this underlying stream.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)