You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by nd...@apache.org on 2013/11/20 03:54:33 UTC

svn commit: r1543700 - in /hbase/branches/0.96/hbase-common/src: main/java/org/apache/hadoop/hbase/util/OrderedBytes.java test/java/org/apache/hadoop/hbase/util/TestOrderedBytes.java

Author: ndimiduk
Date: Wed Nov 20 02:54:33 2013
New Revision: 1543700

URL: http://svn.apache.org/r1543700
Log:
HBASE-9893 Incorrect assert condition in OrderedBytes decoding

Correct an invalid assumption in remaining assertion code around
OrderedBytes#decodeVarBlob. When an encoded value contains a 1-bit in its LSB
position and the length of the encoded byte array is divisible by 7, the value
remaining in variable t will be 0x80, resulting in the failed assertion coming
out of the decoding loop. This patch preserves the assertion for the general
case by resetting 't' at the conclusion of the 7-byte cycle.

Modified:
    hbase/branches/0.96/hbase-common/src/main/java/org/apache/hadoop/hbase/util/OrderedBytes.java
    hbase/branches/0.96/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestOrderedBytes.java

Modified: hbase/branches/0.96/hbase-common/src/main/java/org/apache/hadoop/hbase/util/OrderedBytes.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-common/src/main/java/org/apache/hadoop/hbase/util/OrderedBytes.java?rev=1543700&r1=1543699&r2=1543700&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-common/src/main/java/org/apache/hadoop/hbase/util/OrderedBytes.java (original)
+++ hbase/branches/0.96/hbase-common/src/main/java/org/apache/hadoop/hbase/util/OrderedBytes.java Wed Nov 20 02:54:33 2013
@@ -1109,6 +1109,9 @@ public class OrderedBytes {
       if (s == 7) {
         ret.put((byte) (t | (ord.apply(a[offset + i]) & 0x7f)));
         i++;
+               // explicitly reset t -- clean up overflow buffer after decoding
+               // a full cycle and retain assertion condition below. This happens
+        t = 0; // when the LSB in the last encoded byte is 1. (HBASE-9893)
       } else {
         ret.put((byte) (t | ((ord.apply(a[offset + i]) & 0x7f) >>> s)));
       }

Modified: hbase/branches/0.96/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestOrderedBytes.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.96/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestOrderedBytes.java?rev=1543700&r1=1543699&r2=1543700&view=diff
==============================================================================
--- hbase/branches/0.96/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestOrderedBytes.java (original)
+++ hbase/branches/0.96/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestOrderedBytes.java Wed Nov 20 02:54:33 2013
@@ -872,9 +872,19 @@ public class TestOrderedBytes {
     byte[][] vals =
         { "".getBytes(), "foo".getBytes(), "foobarbazbub".getBytes(),
           { (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa,
+            (byte) 0xaa, /* 7 bytes of alternating bits; testing around HBASE-9893 */ },
+          { (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa,
             (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa },
+          { (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa,
+            (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa, (byte) 0xaa,
+            (byte) 0xaa, (byte) 0xaa, /* 14 bytes of alternating bits; testing around HBASE-9893 */ },
+          { (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55,
+            (byte) 0x55, /* 7 bytes of alternating bits; testing around HBASE-9893 */ },
           { (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55,
             (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55 },
+          { (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55,
+            (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55, (byte) 0x55,
+            (byte) 0x55, (byte) 0x55, /* 14 bytes of alternating bits; testing around HBASE-9893 */ },
           "1".getBytes(), "22".getBytes(), "333".getBytes(), "4444".getBytes(),
           "55555".getBytes(), "666666".getBytes(), "7777777".getBytes(), "88888888".getBytes()
         };