Index: modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/NullCipherTest.java =================================================================== --- modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/NullCipherTest.java (revision 420453) +++ modules/crypto/src/test/api/java/org/apache/harmony/crypto/tests/javax/crypto/NullCipherTest.java (working copy) @@ -182,6 +182,18 @@ } /* + * Class under test for byte[] update(byte[], int, int) + */ + public void testUpdatebyteArrayintint2() { + try { + new NullCipher().update(new byte[1], 1, Integer.MAX_VALUE); + fail("Expected IllegalArgumentException was not thrown."); + } catch (IllegalArgumentException e) { + // expected + } + } + + /* * Class under test for int doFinal(byte[], int, int, byte[]) */ public void testDoFinalbyteArrayintintbyteArray() throws Exception { @@ -192,6 +204,31 @@ } /* + * Class under test for int doFinal(byte[], int, int, byte[]) + */ + public void testDoFinalbyteArrayintintbyteArray2() throws Exception { + try { + new NullCipher().update(new byte[1], 1, Integer.MAX_VALUE, + new byte[1]); + fail("Expected IllegalArgumentException was not thrown."); + } catch (IllegalArgumentException e) { + // expected + } + } + + /* + * Class under test for int doFinal(byte[], int, int, byte[]) + */ + public void testDoFinalbyteArrayintintbyteArray3() throws Exception { + try { + new NullCipher().update(new byte[1], 0, 1, new byte[0]); + fail("Expected ArrayIndexOutOfBoundsException was not thrown."); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + } + + /* * Class under test for int doFinal(byte[], int, int, byte[], int) */ public void testDoFinalbyteArrayintintbyteArrayint() throws Exception { @@ -200,4 +237,30 @@ c.doFinal(b, 0, 5, r, 0); assertTrue("different content", Arrays.equals(b, r)); } + + /* + * Class under test for int doFinal(byte[], int, int, byte[], int) + */ + public void testDoFinalbyteArrayintintbyteArrayint2() throws Exception { + try { + new NullCipher().update(new byte[1], 1, Integer.MAX_VALUE, + new byte[1], 0); + fail("Expected IllegalArgumentException was not thrown."); + } catch (IllegalArgumentException e) { + // expected + } + } + + /* + * Class under test for int doFinal(byte[], int, int, byte[], int) + */ + public void testDoFinalbyteArrayintintbyteArrayint3() throws Exception { + try { + new NullCipher().update(new byte[1], 0, 1, + new byte[0], 0); + fail("Expected ArrayIndexOutOfBoundsException was not thrown."); + } catch (ArrayIndexOutOfBoundsException e) { + // expected + } + } } Index: modules/crypto/src/main/java/javax/crypto/CipherOutputStream.java =================================================================== --- modules/crypto/src/main/java/javax/crypto/CipherOutputStream.java (revision 420453) +++ modules/crypto/src/main/java/javax/crypto/CipherOutputStream.java (working copy) @@ -72,6 +72,9 @@ * @com.intel.drl.spec_ref */ public void write(byte[] b, int off, int len) throws IOException { + if (len == 0) { + return; + } byte[] result; result = cipher.update(b, off, len); if (result != null) { Index: modules/crypto/src/main/java/javax/crypto/Cipher.java =================================================================== --- modules/crypto/src/main/java/javax/crypto/Cipher.java (revision 420453) +++ modules/crypto/src/main/java/javax/crypto/Cipher.java (working copy) @@ -541,6 +541,7 @@ throw new IllegalArgumentException("The input parameter is null"); } if (inputOffset < 0 || inputLen < 0 + || inputLen > input.length || inputOffset + inputLen > input.length) { throw new IllegalArgumentException( "Incorrect inputOffset/inputLen parameters"); @@ -581,6 +582,7 @@ "Incorrect outputOffset parameter"); } if (inputOffset < 0 || inputLen < 0 + || inputLen > input.length || inputOffset + inputLen > input.length) { throw new IllegalArgumentException( "Incorrect inputOffset/inputLen parameters"); @@ -774,4 +776,4 @@ //FIXME jurisdiction policy files return null; } -} \ No newline at end of file +}