changeset 55323:a7abac394abb

8223730: URLClassLoader.findClass() can throw IndexOutOfBoundsException Reviewed-by: prappo, bchristi
author igerasim
date Mon, 13 May 2019 18:18:42 -0700
parents 01fa7f06f806
children 6a60270af76b
files src/java.base/share/classes/jdk/internal/loader/Resource.java
diffstat 1 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/jdk/internal/loader/Resource.java	Tue May 14 08:47:13 2019 +0800
+++ b/src/java.base/share/classes/jdk/internal/loader/Resource.java	Mon May 13 18:18:42 2019 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1998, 2009, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2019, 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
@@ -113,9 +113,11 @@
                 int bytesToRead;
                 if (pos >= b.length) { // Only expand when there's no room
                     bytesToRead = Math.min(len - pos, b.length + 1024);
-                    if (b.length < pos + bytesToRead) {
-                        b = Arrays.copyOf(b, pos + bytesToRead);
+                    if (bytesToRead < 0) {
+                        // Can overflow only due to large b.length
+                        bytesToRead = len - pos;
                     }
+                    b = Arrays.copyOf(b, pos + bytesToRead);
                 } else {
                     bytesToRead = b.length - pos;
                 }