avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject [08/35] avro git commit: AVRO-1888: Java: Fix single-record encoding marker check.
Date Sat, 05 Nov 2016 20:20:25 GMT
AVRO-1888: Java: Fix single-record encoding marker check.


Project: http://git-wip-us.apache.org/repos/asf/avro/repo
Commit: http://git-wip-us.apache.org/repos/asf/avro/commit/fa46c979
Tree: http://git-wip-us.apache.org/repos/asf/avro/tree/fa46c979
Diff: http://git-wip-us.apache.org/repos/asf/avro/diff/fa46c979

Branch: refs/heads/branch-1.8
Commit: fa46c9794767d512522824948f3c792dd634b828
Parents: cd760da
Author: Ryan Blue <blue@apache.org>
Authored: Sat Sep 3 17:25:48 2016 -0700
Committer: Ryan Blue <blue@apache.org>
Committed: Sat Nov 5 13:14:58 2016 -0700

----------------------------------------------------------------------
 CHANGES.txt                                     |  2 ++
 .../avro/message/BinaryMessageDecoder.java      |  4 +--
 .../avro/message/TestBinaryMessageEncoding.java | 38 ++++++++++++++++++++
 3 files changed, 42 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/avro/blob/fa46c979/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 13f897e..9e73997 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -27,6 +27,8 @@ Trunk (not yet released)
     AVRO-607: Java: Make SpecificData schema cache thread-safe.
     (Andrius Druzinis-Vitkus via blue)
 
+    AVRO-1888: Java: Fix single-record encoding marker check. (blue)
+
 Avro 1.8.1 (14 May 2016)
 
   INCOMPATIBLE CHANGES

http://git-wip-us.apache.org/repos/asf/avro/blob/fa46c979/lang/java/avro/src/main/java/org/apache/avro/message/BinaryMessageDecoder.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/main/java/org/apache/avro/message/BinaryMessageDecoder.java
b/lang/java/avro/src/main/java/org/apache/avro/message/BinaryMessageDecoder.java
index 11a7336..af8b8c1 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/message/BinaryMessageDecoder.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/message/BinaryMessageDecoder.java
@@ -157,8 +157,8 @@ public class BinaryMessageDecoder<D> extends MessageDecoder.BaseDecoder<D>
{
       throw new IOException("Failed to read header and fingerprint bytes", e);
     }
 
-    if (! (BinaryMessageEncoder.V1_HEADER[0] == header[0])
-        && BinaryMessageEncoder.V1_HEADER[1] == header[1]) {
+    if (BinaryMessageEncoder.V1_HEADER[0] != header[0] ||
+        BinaryMessageEncoder.V1_HEADER[1] != header[1]) {
       throw new BadHeaderException(String.format(
           "Unrecognized header bytes: 0x%h%h",
           header[0], header[1]));

http://git-wip-us.apache.org/repos/asf/avro/blob/fa46c979/lang/java/avro/src/test/java/org/apache/avro/message/TestBinaryMessageEncoding.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/test/java/org/apache/avro/message/TestBinaryMessageEncoding.java
b/lang/java/avro/src/test/java/org/apache/avro/message/TestBinaryMessageEncoding.java
index 47656b8..91e8eea 100644
--- a/lang/java/avro/src/test/java/org/apache/avro/message/TestBinaryMessageEncoding.java
+++ b/lang/java/avro/src/test/java/org/apache/avro/message/TestBinaryMessageEncoding.java
@@ -238,4 +238,42 @@ public class TestBinaryMessageEncoding {
     decoder.decode(buffer);
   }
 
+  @Test(expected = BadHeaderException.class)
+  public void testByteBufferBadMarkerByte() throws Exception {
+    MessageEncoder<Record> encoder = new BinaryMessageEncoder<Record>(
+        GenericData.get(), SCHEMA_V2);
+    MessageDecoder<Record> decoder = new BinaryMessageDecoder<Record>(
+        GenericData.get(), SCHEMA_V2);
+
+    ByteBuffer buffer = encoder.encode(V2_RECORDS.get(0));
+    buffer.array()[0] = 0x00;
+
+    decoder.decode(buffer);
+  }
+
+  @Test(expected = BadHeaderException.class)
+  public void testByteBufferBadVersionByte() throws Exception {
+    MessageEncoder<Record> encoder = new BinaryMessageEncoder<Record>(
+        GenericData.get(), SCHEMA_V2);
+    MessageDecoder<Record> decoder = new BinaryMessageDecoder<Record>(
+        GenericData.get(), SCHEMA_V2);
+
+    ByteBuffer buffer = encoder.encode(V2_RECORDS.get(0));
+    buffer.array()[1] = 0x00;
+
+    decoder.decode(buffer);
+  }
+
+  @Test(expected = MissingSchemaException.class)
+  public void testByteBufferUnknownSchema() throws Exception {
+    MessageEncoder<Record> encoder = new BinaryMessageEncoder<Record>(
+        GenericData.get(), SCHEMA_V2);
+    MessageDecoder<Record> decoder = new BinaryMessageDecoder<Record>(
+        GenericData.get(), SCHEMA_V2);
+
+    ByteBuffer buffer = encoder.encode(V2_RECORDS.get(0));
+    buffer.array()[4] = 0x00;
+
+    decoder.decode(buffer);
+  }
 }


Mime
View raw message