Skip to content
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

8286978: SIGBUS in libz during CDS initialization #8799

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -232,7 +232,7 @@ public static void main(String... args) throws Exception {
// insert bytes in data section
System.out.println("\n5. Insert bytes at beginning of data section, should fail\n");
String insertBytes = startNewArchive("insert-bytes");
CDSArchiveUtils.insertBytesRandomlyAfterHeader(orgJsaFile, insertBytes, new byte[4096]);
CDSArchiveUtils.insertBytesRandomlyAfterHeader(orgJsaFile, insertBytes);
testAndCheck(verifyExecArgs);

// delete bytes in data section forward
@@ -409,18 +409,41 @@ public static long writeData(File file, long offset, int value) throws Exception
}
}

// dstFile will keep original size so will remove corresponding bytes.length bytes at end of file
public static File insertBytesRandomlyAfterHeader(File orgFile, String newFileName, byte[] bytes) throws Exception {
long offset = fileHeaderSize(orgFile) + getRandomBetween(0L, 4096L);
// Helper method for calling FileChannel.transferFrom and checking the
// return value.
private static void transferFrom(FileChannel inputChannel,
FileChannel outputChannel,
long offset,
long length) throws Exception {
long position = offset;
long count = length;
while (count > 0 && inputChannel.position() < inputChannel.size()) {
long n = outputChannel.transferFrom(inputChannel, position, count);
if (n < 0 || n > count) {
throw new RuntimeException("Incorrect transfer length n = " + n
+ " (expected 0 <= n <= " + length + ")");
}
position += n;
count -= n;
}
}

// dstFile will keep original size
public static File insertBytesRandomlyAfterHeader(File orgFile, String newFileName) throws Exception {
long headerSize = fileHeaderSize(orgFile);
long dupSize = getRandomBetween(0L, headerSize);
File dstFile = new File(newFileName);
try (FileChannel inputChannel = new FileInputStream(orgFile).getChannel();
FileChannel outputChannel = new FileOutputStream(dstFile).getChannel()) {
long orgSize = inputChannel.size();
outputChannel.transferFrom(inputChannel, 0, offset);
outputChannel.position(offset);
outputChannel.write(ByteBuffer.wrap(bytes));
outputChannel.transferFrom(inputChannel, offset + bytes.length, orgSize - bytes.length);
}
// Copy the header
transferFrom(inputChannel, outputChannel, 0, headerSize);
// Copy dupSize bytes from the end of the header. Then, copy the rest
// of the input such that the new file will have the same size as
// the old file.
inputChannel.position(headerSize - dupSize);
transferFrom(inputChannel, outputChannel, headerSize, orgSize - headerSize);
}
return dstFile;
}

@@ -431,9 +454,9 @@ public static File deleteBytesAtRandomPositionAfterHeader(File orgFile, String n
try (FileChannel inputChannel = new FileInputStream(orgFile).getChannel();
FileChannel outputChannel = new FileOutputStream(dstFile).getChannel()) {
long orgSize = inputChannel.size();
outputChannel.transferFrom(inputChannel, 0, offset);
transferFrom(inputChannel, outputChannel, 0, offset);
inputChannel.position(offset + nBytes);
outputChannel.transferFrom(inputChannel, offset, orgSize - nBytes);
transferFrom(inputChannel, outputChannel, offset, orgSize - nBytes);
}
return dstFile;
}