RFR: 8245036: DataInputStream.readFully(byte[], int, int) does not throw expected IndexOutOfBoundsExceptions
Raffaello Giulietti
raffaello.giulietti at gmail.com
Thu Aug 6 21:36:04 UTC 2020
Hi Brian,
the body of readFully() seems to silently assume that the other
arguments are correct (e.g., off >= 0 and so on).
In the (still) current implementation of
DataInputStream.readFully(byte[], int, int), when off < 0 and len > 0,
in the loop it then invokes the underlying in.read(byte[], int, int)
with a negative offset off + n during the initial iterations.
In the specific case of the tests on underlying FileInputStreams, it
thus seems that read(byte[], int, int) does not, in turn, validate its
arguments. I didn't investigate further, although I will in the next
days if deemed necessary.
Greetings
Raffaello
On 2020-08-06 22:09, Brian Burkhalter wrote:
>
>> On Aug 6, 2020, at 12:36 PM, Raffaello Giulietti
>> <raffaello.giulietti at gmail.com <mailto:raffaello.giulietti at gmail.com>>
>> wrote:
>>
>>> This looks all right. I would be inclined to do like in [1] and throw
>>> the RuntimeException on the line after each readFully() and drop the
>>> return statements], but I’m not going to insist on it.
>>> Thanks,
>>> Brian
>>> [1]http://hg.openjdk.java.net/jdk/jdk/file/db6952bf8c39/test/jdk/java/nio/file/etc/MacVolumesTest.java#l58
>>
>> Sorry, I didn't completely get that.
>> Here we are!
>
> This looks good. I observed however that the test passes without the
> change to DataInputStream.
>
> Brian
More information about the core-libs-dev
mailing list