New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8190753: (zipfs): Accessing a large entry (> 2^31 bytes) leads to a negative initial size for ByteArrayOutputStream #4607
Closed
Closed
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8d6f340
8190753: (zipfs): Accessing a large entry (> 2^31 bytes) leads to a n…
jaikiran 127acbc
add @requires to the new test to selectively decide where the test runs
jaikiran 19cc9d4
minor summary update on test
jaikiran f519aa4
an initial proposed test for testing compressed size entry greater th…
jaikiran 5c5f269
Introduce a way to allow outputstream returned by ZipOutputStream to …
jaikiran a9dfd8c
propagate back the original checked IOException to the callers
jaikiran c27a0a4
Implement Alan's review suggestion - don't expose the threshold as a …
jaikiran 9de70ef
use jtreg's construct of manual test
jaikiran 50e64d7
remove no longer used constant
jaikiran 0fdbcea
minor update to comment on FileRolloverOutputStream class
jaikiran c1ec9e1
reorganize the tests now that the temp file creation threshold isn't …
jaikiran b6d453f
review suggestion - wrap ByteArrayOutputStream instead of extending it
jaikiran 90101d4
remove no longer necessary javadoc comment on test
jaikiran 9e78ba0
Implement review suggestions:
jaikiran 991de6b
Merge latest from master branch
jaikiran File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
* or visit www.oracle.com if you need additional information or have any | ||
* questions. | ||
* | ||
*/ | ||
|
||
import org.testng.annotations.AfterMethod; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.file.FileSystem; | ||
import java.nio.file.FileSystems; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
import java.util.Random; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* @test | ||
* @bug 8190753 8011146 | ||
* @summary Verify that using zip filesystem for opening an outputstream for a zip entry whose | ||
* compressed size is large, doesn't run into "Negative initial size" exception | ||
* @run testng/manual/othervm LargeCompressedEntrySizeTest | ||
*/ | ||
public class LargeCompressedEntrySizeTest { | ||
|
||
private static final String LARGE_FILE_NAME = "LargeZipEntry.txt"; | ||
private static final String ZIP_FILE_NAME = "8190753-test-compressed-size.zip"; | ||
|
||
@BeforeMethod | ||
public void setUp() throws IOException { | ||
deleteFiles(); | ||
} | ||
|
||
@AfterMethod | ||
public void tearDown() throws IOException { | ||
deleteFiles(); | ||
} | ||
|
||
/** | ||
* Delete the files created for use by the test | ||
* | ||
* @throws IOException if an error occurs deleting the files | ||
*/ | ||
private static void deleteFiles() throws IOException { | ||
Files.deleteIfExists(Path.of(ZIP_FILE_NAME)); | ||
} | ||
|
||
|
||
/** | ||
* Using zip filesystem, creates a zip file and writes out a zip entry whose compressed size is | ||
* expected to be greater than 2gb. | ||
*/ | ||
@Test | ||
public void testLargeCompressedSizeWithZipFS() throws Exception { | ||
final Path zipFile = Path.of(ZIP_FILE_NAME); | ||
final long largeEntrySize = 6L * 1024L * 1024L * 1024L; // large value which exceeds Integer.MAX_VALUE | ||
try (FileSystem fs = FileSystems.newFileSystem(zipFile, Collections.singletonMap("create", "true"))) { | ||
try (OutputStream os = Files.newOutputStream(fs.getPath(LARGE_FILE_NAME))) { | ||
long remaining = largeEntrySize; | ||
// create a chunk of random bytes which we keep writing out | ||
final int chunkSize = 102400; | ||
final byte[] chunk = new byte[chunkSize]; | ||
new Random().nextBytes(chunk); | ||
final long start = System.currentTimeMillis(); | ||
for (long l = 0; l < largeEntrySize; l += chunkSize) { | ||
final int numToWrite = (int) Math.min(remaining, chunkSize); | ||
os.write(chunk, 0, numToWrite); | ||
remaining -= numToWrite; | ||
} | ||
System.out.println("Took " + TimeUnit.SECONDS.toSeconds(System.currentTimeMillis() - start) | ||
+ " seconds to generate entry of size " + largeEntrySize); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proposed change will address the specific issue shown in the bug. As Alan points out, there could be an issue if the deflated size is > 2gb. It would be good to look into that as part of your proposed fix.