< prev index next >

src/java.base/share/classes/jdk/internal/jimage/ImageStringsReader.java

Print this page
rev 14631 : 8156209: Add argument checks to BasicImageReader calls
Reviewed-by: sundar

*** 25,34 **** --- 25,35 ---- package jdk.internal.jimage; import java.io.UTFDataFormatException; import java.nio.ByteBuffer; + import java.util.Objects; /** * @implNote This class needs to maintain JDK 8 source compatibility. * * It is used internally in the JDK to implement jimage/jrtfs access,
*** 38,47 **** --- 39,49 ---- public class ImageStringsReader implements ImageStrings { public static final int HASH_MULTIPLIER = 0x01000193; private final BasicImageReader reader; ImageStringsReader(BasicImageReader reader) { + Objects.requireNonNull(reader); this.reader = reader; } @Override public String get(int offset) {
*** 52,62 **** public int add(final String string) { throw new InternalError("Can not add strings at runtime"); } private static int hashCode(byte[] bytes, int offset, int count, int seed) { ! for (int i = offset, limit = offset + count; i < limit; i++) { seed = (seed * HASH_MULTIPLIER) ^ (bytes[i] & 0xFF); } return seed & 0x7FFFFFFF; } --- 54,76 ---- public int add(final String string) { throw new InternalError("Can not add strings at runtime"); } private static int hashCode(byte[] bytes, int offset, int count, int seed) { ! Objects.requireNonNull(bytes); ! ! if (offset < 0 || offset >= bytes.length) { ! throw new IndexOutOfBoundsException("offset"); ! } ! ! int limit = offset + count; ! ! if (limit < 0 || limit > bytes.length) { ! throw new IndexOutOfBoundsException("limit"); ! } ! ! for (int i = offset; i < limit; i++) { seed = (seed * HASH_MULTIPLIER) ^ (bytes[i] & 0xFF); } return seed & 0x7FFFFFFF; }
< prev index next >