avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r1445325 - in /avro/trunk: CHANGES.txt lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java lang/java/avro/src/test/java/org/apache/avro/io/TestBinaryDecoder.java
Date Tue, 12 Feb 2013 19:42:37 GMT
Author: cutting
Date: Tue Feb 12 19:42:36 2013
New Revision: 1445325

URL: http://svn.apache.org/r1445325
Log:
AVRO-1198. Java: Improve error message for malformed data.

Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java
    avro/trunk/lang/java/avro/src/test/java/org/apache/avro/io/TestBinaryDecoder.java

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=1445325&r1=1445324&r2=1445325&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Tue Feb 12 19:42:36 2013
@@ -30,6 +30,8 @@ Trunk (not yet released)
 
     AVRO-1241. Java: Optimize Trevni string input. (Joseph Adler via cutting)
 
+    AVRO-1198. Java: Improve error message for malformed data. (cutting)
+
   BUG FIXES
 
     AVRO-1231. Java: Fix Trevni shredder to work on non-recursive

Modified: avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java?rev=1445325&r1=1445324&r2=1445325&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java (original)
+++ avro/trunk/lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java Tue Feb
12 19:42:36 2013
@@ -22,6 +22,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.nio.ByteBuffer;
 
+import org.apache.avro.AvroRuntimeException;
 import org.apache.avro.util.Utf8;
 
 /** An {@link Decoder} for binary-format data.
@@ -331,6 +332,9 @@ public class BinaryDecoder extends Decod
    */
   protected void doReadBytes(byte[] bytes, int start, int length)
       throws IOException {
+    if (length < 0)
+      throw new AvroRuntimeException("Malformed data. Length is negative: "
+                                     + length);
     int remaining = limit - pos;
     if (length <= remaining) {
       System.arraycopy(buf, pos, bytes, start, length);

Modified: avro/trunk/lang/java/avro/src/test/java/org/apache/avro/io/TestBinaryDecoder.java
URL: http://svn.apache.org/viewvc/avro/trunk/lang/java/avro/src/test/java/org/apache/avro/io/TestBinaryDecoder.java?rev=1445325&r1=1445324&r2=1445325&view=diff
==============================================================================
--- avro/trunk/lang/java/avro/src/test/java/org/apache/avro/io/TestBinaryDecoder.java (original)
+++ avro/trunk/lang/java/avro/src/test/java/org/apache/avro/io/TestBinaryDecoder.java Tue
Feb 12 19:42:36 2013
@@ -29,6 +29,7 @@ import java.util.Collection;
 
 import org.apache.avro.RandomData;
 import org.apache.avro.Schema;
+import org.apache.avro.AvroRuntimeException;
 import org.apache.avro.generic.GenericDatumReader;
 import org.apache.avro.generic.GenericDatumWriter;
 import org.apache.avro.util.ByteBufferInputStream;
@@ -356,6 +357,19 @@ public class TestBinaryDecoder {
     Assert.assertEquals("Invalid long encoding", message);
   }
 
+  @Test
+  public void testBadLengthEncoding() throws IOException {
+    byte[] bad = new byte[] { (byte)1 };
+    Decoder bd = factory.binaryDecoder(bad, null);
+    String message = "";
+    try {
+      bd.readString();
+    } catch (AvroRuntimeException e) {
+      message = e.getMessage();
+    }
+    Assert.assertEquals("Malformed data. Length is negative: -1", message);
+  }
+
   @Test(expected=EOFException.class)
   public void testIntTooShort() throws IOException {
     byte[] badint = new byte[4];



Mime
View raw message