Skip to content

Apache Lucene open-source search software

LUCENE-6591: never write a negative vlong

Michael McCandlessc9e267f9481c
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index fb1edea43b6..0f3fdffe418 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -158,6 +158,9 @@ Bug fixes
* LUCENE-6593: Fixed ToChildBlockJoinQuery's scorer to not refuse to advance
to a document that belongs to the parent space. (Adrien Grand)
+* LUCENE-6591: Never write a negative vLong (Robert Muir, Ryan Ernst,
+ Adrien Grand, Mike McCandless)
+
Changes in Runtime Behavior
* LUCENE-6501: The subreader structure in ParallelCompositeReader
diff --git a/lucene/core/src/java/org/apache/lucene/store/DataOutput.java b/lucene/core/src/java/org/apache/lucene/store/DataOutput.java
index 4daf284be17..efdba774694 100644
--- a/lucene/core/src/java/org/apache/lucene/store/DataOutput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/DataOutput.java
@@ -221,12 +221,14 @@ public abstract class DataOutput {
* @see DataInput#readVLong()
*/
public final void writeVLong(long i) throws IOException {
- assert i >= 0L;
- writeNegativeVLong(i);
+ if (i < 0) {
+ throw new IllegalArgumentException("cannot write negative vLong (got: " + i + ")");
+ }
+ writeSignedVLong(i);
}
- // write a pontentially negative vLong
- private void writeNegativeVLong(long i) throws IOException {
+ // write a potentially negative vLong
+ private void writeSignedVLong(long i) throws IOException {
while ((i & ~0x7FL) != 0L) {
writeByte((byte)((i & 0x7FL) | 0x80L));
i >>>= 7;
@@ -241,7 +243,7 @@ public abstract class DataOutput {
* @see DataInput#readZLong()
*/
public final void writeZLong(long i) throws IOException {
- writeNegativeVLong(BitUtil.zigZagEncode(i));
+ writeSignedVLong(BitUtil.zigZagEncode(i));
}
/** Writes a string.