diff --git a/lucene/core/src/java/org/apache/lucene/store/BufferedIndexInput.java b/lucene/core/src/java/org/apache/lucene/store/BufferedIndexInput.java index e7fad524594..1ff8f34e11a 100644 --- a/lucene/core/src/java/org/apache/lucene/store/BufferedIndexInput.java +++ b/lucene/core/src/java/org/apache/lucene/store/BufferedIndexInput.java @@ -199,17 +199,17 @@ public abstract class BufferedIndexInput extends IndexInput { public final int readVInt() throws IOException { if (5 <= (bufferLength-bufferPosition)) { byte b = buffer[bufferPosition++]; + if (b >= 0) return b; int i = b & 0x7F; - if ((b & 0x80) == 0) return i; b = buffer[bufferPosition++]; i |= (b & 0x7F) << 7; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = buffer[bufferPosition++]; i |= (b & 0x7F) << 14; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = buffer[bufferPosition++]; i |= (b & 0x7F) << 21; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = buffer[bufferPosition++]; // Warning: the next ands use 0x0F / 0xF0 - beware copy/paste errors: i |= (b & 0x0F) << 28; @@ -224,32 +224,32 @@ public abstract class BufferedIndexInput extends IndexInput { public final long readVLong() throws IOException { if (9 <= bufferLength-bufferPosition) { byte b = buffer[bufferPosition++]; + if (b >= 0) return b; long i = b & 0x7FL; - if ((b & 0x80) == 0) return i; b = buffer[bufferPosition++]; i |= (b & 0x7FL) << 7; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = buffer[bufferPosition++]; i |= (b & 0x7FL) << 14; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = buffer[bufferPosition++]; i |= (b & 0x7FL) << 21; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = buffer[bufferPosition++]; i |= (b & 0x7FL) << 28; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = buffer[bufferPosition++]; i |= (b & 0x7FL) << 35; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = buffer[bufferPosition++]; i |= (b & 0x7FL) << 42; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = buffer[bufferPosition++]; i |= (b & 0x7FL) << 49; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = buffer[bufferPosition++]; i |= (b & 0x7FL) << 56; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; throw new IOException("Invalid vLong detected (negative values disallowed)"); } else { return super.readVLong(); diff --git a/lucene/core/src/java/org/apache/lucene/store/ByteArrayDataInput.java b/lucene/core/src/java/org/apache/lucene/store/ByteArrayDataInput.java index 7be30258d5d..d19c3bb6593 100644 --- a/lucene/core/src/java/org/apache/lucene/store/ByteArrayDataInput.java +++ b/lucene/core/src/java/org/apache/lucene/store/ByteArrayDataInput.java @@ -102,17 +102,17 @@ public final class ByteArrayDataInput extends DataInput { @Override public int readVInt() { byte b = bytes[pos++]; + if (b >= 0) return b; int i = b & 0x7F; - if ((b & 0x80) == 0) return i; b = bytes[pos++]; i |= (b & 0x7F) << 7; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = bytes[pos++]; i |= (b & 0x7F) << 14; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = bytes[pos++]; i |= (b & 0x7F) << 21; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = bytes[pos++]; // Warning: the next ands use 0x0F / 0xF0 - beware copy/paste errors: i |= (b & 0x0F) << 28; @@ -123,32 +123,32 @@ public final class ByteArrayDataInput extends DataInput { @Override public long readVLong() { byte b = bytes[pos++]; + if (b >= 0) return b; long i = b & 0x7FL; - if ((b & 0x80) == 0) return i; b = bytes[pos++]; i |= (b & 0x7FL) << 7; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = bytes[pos++]; i |= (b & 0x7FL) << 14; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = bytes[pos++]; i |= (b & 0x7FL) << 21; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = bytes[pos++]; i |= (b & 0x7FL) << 28; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = bytes[pos++]; i |= (b & 0x7FL) << 35; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = bytes[pos++]; i |= (b & 0x7FL) << 42; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = bytes[pos++]; i |= (b & 0x7FL) << 49; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = bytes[pos++]; i |= (b & 0x7FL) << 56; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; throw new RuntimeException("Invalid vLong detected (negative values disallowed)"); } diff --git a/lucene/core/src/java/org/apache/lucene/store/DataInput.java b/lucene/core/src/java/org/apache/lucene/store/DataInput.java index 4ee6ddfcd52..6d2e621efb3 100644 --- a/lucene/core/src/java/org/apache/lucene/store/DataInput.java +++ b/lucene/core/src/java/org/apache/lucene/store/DataInput.java @@ -94,17 +94,17 @@ public abstract class DataInput implements Cloneable { return i; */ byte b = readByte(); + if (b >= 0) return b; int i = b & 0x7F; - if ((b & 0x80) == 0) return i; b = readByte(); i |= (b & 0x7F) << 7; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = readByte(); i |= (b & 0x7F) << 14; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = readByte(); i |= (b & 0x7F) << 21; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = readByte(); // Warning: the next ands use 0x0F / 0xF0 - beware copy/paste errors: i |= (b & 0x0F) << 28; @@ -135,32 +135,32 @@ public abstract class DataInput implements Cloneable { return i; */ byte b = readByte(); + if (b >= 0) return b; long i = b & 0x7FL; - if ((b & 0x80) == 0) return i; b = readByte(); i |= (b & 0x7FL) << 7; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = readByte(); i |= (b & 0x7FL) << 14; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = readByte(); i |= (b & 0x7FL) << 21; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = readByte(); i |= (b & 0x7FL) << 28; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = readByte(); i |= (b & 0x7FL) << 35; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = readByte(); i |= (b & 0x7FL) << 42; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = readByte(); i |= (b & 0x7FL) << 49; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; b = readByte(); i |= (b & 0x7FL) << 56; - if ((b & 0x80) == 0) return i; + if (b >= 0) return i; throw new IOException("Invalid vLong detected (negative values disallowed)"); }