8228407: JVM crashes with shared archive file mismatch

Stop processing other header fields if initial header check has failed.

Reviewed-by: dholmes, jiangli
This commit is contained in:
Calvin Cheung 2019-07-25 10:25:52 -07:00
parent 3476b6dab8
commit fc7aa2306c
2 changed files with 13 additions and 3 deletions

View file

@ -1610,7 +1610,9 @@ bool FileMapInfo::initialize(bool is_static) {
} }
init_from_file(_fd, is_static); init_from_file(_fd, is_static);
if (!validate_header(is_static)) { // UseSharedSpaces could be disabled if the checking of some of the header fields in
// init_from_file has failed.
if (!UseSharedSpaces || !validate_header(is_static)) {
return false; return false;
} }
return true; return true;

View file

@ -417,9 +417,17 @@ public class SharedArchiveConsistency {
output.shouldContain("The shared archive file was created by a different version or build of HotSpot"); output.shouldContain("The shared archive file was created by a different version or build of HotSpot");
output.shouldNotContain("Checksum verification failed"); output.shouldNotContain("Checksum verification failed");
copyFile(orgJsaFile, jsa);
// modify _jvm_ident and run with -Xshare:auto
System.out.println("\n2b. Corrupt _jvm_ident run with -Xshare:auto\n");
modifyJvmIdent();
output = TestCommon.execAuto(execArgs);
output.shouldContain("The shared archive file was created by a different version or build of HotSpot");
output.shouldContain("Hello World");
copyFile(orgJsaFile, jsa); copyFile(orgJsaFile, jsa);
// modify _magic and _paths_misc_info_size, test should fail // modify _magic and _paths_misc_info_size, test should fail
System.out.println("\n2b. Corrupt _magic and _paths_misc_info_size, should fail\n"); System.out.println("\n2c. Corrupt _magic and _paths_misc_info_size, should fail\n");
modifyHeaderIntField(offset_magic, 0x00000000); modifyHeaderIntField(offset_magic, 0x00000000);
modifyHeaderIntField(offset_paths_misc_info_size, Integer.MAX_VALUE); modifyHeaderIntField(offset_paths_misc_info_size, Integer.MAX_VALUE);
output = TestCommon.execCommon(execArgs); output = TestCommon.execCommon(execArgs);
@ -428,7 +436,7 @@ public class SharedArchiveConsistency {
copyFile(orgJsaFile, jsa); copyFile(orgJsaFile, jsa);
// modify _version and _paths_misc_info_size, test should fail // modify _version and _paths_misc_info_size, test should fail
System.out.println("\n2c. Corrupt _version and _paths_misc_info_size, should fail\n"); System.out.println("\n2d. Corrupt _version and _paths_misc_info_size, should fail\n");
modifyHeaderIntField(offset_version, 0x00000000); modifyHeaderIntField(offset_version, 0x00000000);
modifyHeaderIntField(offset_paths_misc_info_size, Integer.MAX_VALUE); modifyHeaderIntField(offset_paths_misc_info_size, Integer.MAX_VALUE);
output = TestCommon.execCommon(execArgs); output = TestCommon.execCommon(execArgs);