8294702: BufferedInputStream uses undefined value range for markpos

Reviewed-by: alanb, bpb
This commit is contained in:
Markus Karg 2022-10-11 16:07:31 +00:00 committed by Brian Burkhalter
parent 9d0009e92b
commit 619cd825b5

View File

@ -223,7 +223,7 @@ public class BufferedInputStream extends FilterInputStream {
*/
private void fill() throws IOException {
byte[] buffer = getBufIfOpen();
if (markpos < 0)
if (markpos == -1)
pos = 0; /* no mark: throw away the buffer */
else if (pos >= buffer.length) { /* no room left in buffer */
if (markpos > 0) { /* can throw away early part of the buffer */
@ -306,7 +306,7 @@ public class BufferedInputStream extends FilterInputStream {
if there is no mark/reset activity, do not bother to copy the
bytes into the local buffer. In this way buffered streams will
cascade harmlessly. */
if (len >= getBufIfOpen().length && markpos < 0) {
if (len >= getBufIfOpen().length && markpos == -1) {
return getInIfOpen().read(b, off, len);
}
fill();
@ -427,7 +427,7 @@ public class BufferedInputStream extends FilterInputStream {
if (avail <= 0) {
// If no mark position set then don't keep in buffer
if (markpos <0)
if (markpos == -1)
return getInIfOpen().skip(n);
// Fill in buffer to save bytes for reset