Skip to content

Commit 1836962

Browse files
Aleksei VoitylovRealCLanger
authored andcommitted
8370986: Enhance Zip file reading
Reviewed-by: abakhtin Backport-of: 0e46b6b0c682a6a4dd09d74bad4e7283fae4f479
1 parent 266b72e commit 1836962

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/hotspot/share/classfile/classLoader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ ClassPathEntry* ClassLoader::create_class_path_entry(JavaThread* current,
749749
#if INCLUDE_CDS
750750
ClassLoaderExt::set_has_non_jar_in_classpath();
751751
#endif
752+
log_info(class, path)("failed: %s, err: %s", path, error_msg);
752753
return nullptr;
753754
}
754755
log_info(class, path)("opened: %s", path);

src/java.base/share/native/libzip/zip_util.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ static jlong
575575
readCEN(jzfile *zip, jint knownTotal)
576576
{
577577
/* Following are unsigned 32-bit */
578-
jlong endpos, end64pos, cenpos, cenlen, cenoff;
578+
jlong endpos, end64pos, cenpos, cenlen, cenoff, total64;
579579
/* Following are unsigned 16-bit */
580580
jint total, tablelen, i, j;
581581
unsigned char *cenbuf = NULL;
@@ -609,7 +609,16 @@ readCEN(jzfile *zip, jint knownTotal)
609609
if ((end64pos = findEND64(zip, end64buf, endpos)) != -1) {
610610
cenlen = ZIP64_ENDSIZ(end64buf);
611611
cenoff = ZIP64_ENDOFF(end64buf);
612-
total = (jint)ZIP64_ENDTOT(end64buf);
612+
total64 = ZIP64_ENDTOT(end64buf);
613+
/* ZIP64 size, offset and total-count fields are unsigned 64-bit
614+
* values. Sizes and offsets that do not fit in signed jlong
615+
* (i.e., >= 2^63), or total values that do not fit in jint, are
616+
* not supported and indicate a corrupt or invalid zip file.
617+
*/
618+
if (cenlen < 0 || cenoff < 0 || total64 < 0 || total64 > INT_MAX) {
619+
ZIP_FORMAT_ERROR("Zip64 END values exceed supported size");
620+
}
621+
total = (jint)total64;
613622
endpos = end64pos;
614623
endhdrlen = ZIP64_ENDHDR;
615624
}

0 commit comments

Comments
 (0)