<div dir="ltr"><div>Why not make a different utility method for this case. <br></div><br> readRemaining() vs. readFully(int)<br><div><br>The name makes not much sense and the code does not get easier if both cases are in one method for no good reason.<br><br></div><div>And I wonder if allocating a MAXINTEGER buffer from untrusted source is a good idea.<br><br></div><div>Gruss<br></div><div>Bernd<br></div><div><div class="gmail_extra"><br><div class="gmail_quote">2017-07-20 15:49 GMT+02:00 Adam Petcher <span dir="ltr"><<a href="mailto:adam.petcher@oracle.com" target="_blank">adam.petcher@oracle.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Oops. Better to throw an IOException when a negative length is given to readFully.<br>
<br>
Webrev: <a href="http://cr.openjdk.java.net/~apetcher/8183591/webrev.02/" rel="noreferrer" target="_blank">http://cr.openjdk.java.net/~ap<wbr>etcher/8183591/webrev.02/</a><div class="HOEnZb"><div class="h5"><br>
<br>
<br>
On 7/18/2017 1:55 PM, Adam Petcher wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Some additional investigation revealed that IOUtils.readFully() is only used by DER, JKS, and Kerberos. None of these need the "read to the end of the buffer" feature. This behavior of readFully() is confusing, so it is probably best to remove it.<br>
<br>
Webrev: <a href="http://cr.openjdk.java.net/~apetcher/8183591/webrev.01/" rel="noreferrer" target="_blank">http://cr.openjdk.java.net/~ap<wbr>etcher/8183591/webrev.01/</a><br>
<br>
<br>
On 7/12/2017 2:38 PM, Adam Petcher wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
This is a bug fix for a corner case in which a DER value has length equal to Integer.MAX_VALUE. The code uses IOUtils.readFully() to read the value, which interprets length=Integer.MAX_VALUE to mean "read to the end." The result is that no exception will be thrown when fewer then Integer.MAX_VALUE bytes are read from the stream. The fix adds a check after the readFully() to ensure that the expected number of bytes were read.<br>
<br>
Webrev: <a href="http://cr.openjdk.java.net/~apetcher/8183591/webrev.00/" rel="noreferrer" target="_blank">http://cr.openjdk.java.net/~ap<wbr>etcher/8183591/webrev.00/</a><br>
JBS: <a href="https://bugs.openjdk.java.net/browse/JDK-8183591" rel="noreferrer" target="_blank">https://bugs.openjdk.java.net/<wbr>browse/JDK-8183591</a><br>
<br>
</blockquote>
<br>
</blockquote>
<br>
</div></div></blockquote></div><br></div></div></div>