< prev index next >
test/sun/security/util/DerValue/BadValue.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2009, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2009, 2017 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 46,79 ****
// But only 6 left
bs = IOUtils.readFully(in, 10, false);
if (bs.length != 6 || in.available() != 0) {
throw new Exception("Second read error");
}
! // MAX read as much as it can
in = new ByteArrayInputStream(new byte[10]);
bs = IOUtils.readFully(in, Integer.MAX_VALUE, true);
! if (bs.length != 10 || in.available() != 0) {
! throw new Exception("Second read error");
}
! // MAX ignore readAll
in = new ByteArrayInputStream(new byte[10]);
! bs = IOUtils.readFully(in, Integer.MAX_VALUE, false);
! if (bs.length != 10 || in.available() != 0) {
! throw new Exception("Second read error");
}
// 20>10, readAll means failure
in = new ByteArrayInputStream(new byte[10]);
try {
bs = IOUtils.readFully(in, 20, true);
! throw new Exception("Third read error");
} catch (EOFException e) {
// OK
}
int bignum = 10 * 1024 * 1024;
! bs = IOUtils.readFully(new SuperSlowStream(bignum), -1, true);
if (bs.length != bignum) {
! throw new Exception("Fourth read error");
}
// Test DerValue
byte[] input = {0x04, (byte)0x84, 0x40, 0x00, 0x42, 0x46, 0x4b};
try {
--- 46,88 ----
// But only 6 left
bs = IOUtils.readFully(in, 10, false);
if (bs.length != 6 || in.available() != 0) {
throw new Exception("Second read error");
}
! // MAX length results in exception
in = new ByteArrayInputStream(new byte[10]);
+ try {
bs = IOUtils.readFully(in, Integer.MAX_VALUE, true);
! throw new Exception("No exception on MAX_VALUE length");
! } catch (EOFException ex) {
! // this is expected
! } catch (Exception ex) {
! throw ex;
}
! // -1 length results in exception
in = new ByteArrayInputStream(new byte[10]);
! try {
! bs = IOUtils.readFully(in, -1, true);
! throw new Exception("No exception on -1 length");
! } catch (IndexOutOfBoundsException ex) {
! // this is expected
! } catch (Exception ex) {
! throw ex;
}
+
// 20>10, readAll means failure
in = new ByteArrayInputStream(new byte[10]);
try {
bs = IOUtils.readFully(in, 20, true);
! throw new Exception("No exception on EOF");
} catch (EOFException e) {
// OK
}
int bignum = 10 * 1024 * 1024;
! bs = IOUtils.readFully(new SuperSlowStream(bignum), bignum, true);
if (bs.length != bignum) {
! throw new Exception("Read returned small array");
}
// Test DerValue
byte[] input = {0x04, (byte)0x84, 0x40, 0x00, 0x42, 0x46, 0x4b};
try {
< prev index next >