Hello! Having a unit-test would be nice!
With best regards, Tagir Valeev. On Tue, Jul 28, 2020 at 9:04 PM Raffaello Giulietti <raffaello.giulie...@gmail.com> wrote: > > Hello, > > here's a very simple patch to address issue 8245036. > HTH > > > Greetings > Raffaello > > ---- > > # HG changeset patch > # User lello > # Date 1595944637 -7200 > # Tue Jul 28 15:57:17 2020 +0200 > # Node ID 1d66b831e5e2085fca5c3f71ca958c482d4aebd7 > # Parent 89fe9e02a522b57c356f0dd5279085a075c2945b > Patch to fix JDK-8245036 > 8245036: DataInputStream.readFully(byte[], int, int) does not throw > expected IndexOutOfBoundsExceptions > Reviewed-by: TBD > Contributed-by: Raffaello Giulietti <raffaello.giulie...@gmail.com> > > diff --git a/src/java.base/share/classes/java/io/DataInputStream.java > b/src/java.base/share/classes/java/io/DataInputStream.java > --- a/src/java.base/share/classes/java/io/DataInputStream.java > +++ b/src/java.base/share/classes/java/io/DataInputStream.java > @@ -1,5 +1,5 @@ > /* > - * Copyright (c) 1994, 2019, Oracle and/or its affiliates. All rights > reserved. > + * Copyright (c) 1994, 2020, 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 > @@ -25,6 +25,8 @@ > > package java.io; > > +import java.util.Objects; > + > /** > * A data input stream lets an application read primitive Java data > * types from an underlying input stream in a machine-independent > @@ -192,8 +194,7 @@ > * @see java.io.FilterInputStream#in > */ > public final void readFully(byte b[], int off, int len) throws > IOException { > - if (len < 0) > - throw new IndexOutOfBoundsException(); > + Objects.checkFromIndexSize(off, len, b.length); > int n = 0; > while (n < len) { > int count = in.read(b, off + n, len - n);