avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ham...@apache.org
Subject svn commit: r953186 - in /avro/trunk: CHANGES.txt lang/py/src/avro/io.py
Date Wed, 09 Jun 2010 23:17:54 GMT
Author: hammer
Date: Wed Jun  9 23:17:54 2010
New Revision: 953186

URL: http://svn.apache.org/viewvc?rev=953186&view=rev
Log:
AVRO-571. Fix how we handle out-of-bounds indexes for union and
enum parsing in Python (hammer)


Modified:
    avro/trunk/CHANGES.txt
    avro/trunk/lang/py/src/avro/io.py

Modified: avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/avro/trunk/CHANGES.txt?rev=953186&r1=953185&r2=953186&view=diff
==============================================================================
--- avro/trunk/CHANGES.txt (original)
+++ avro/trunk/CHANGES.txt Wed Jun  9 23:17:54 2010
@@ -40,6 +40,9 @@ Avro 1.4.0 (unreleased)
     AVRO-566. Java: fix so that JAVA_HOME is bound by build.xml for
     test_tools.sh.  (cutting)
 
+    AVRO-571. Fix how we handle out-of-bounds indexes for union and 
+    enum parsing in Python (hammer)
+
 Avro 1.3.3 (7 June 2010)
 
   IMPROVEMENTS

Modified: avro/trunk/lang/py/src/avro/io.py
URL: http://svn.apache.org/viewvc/avro/trunk/lang/py/src/avro/io.py?rev=953186&r1=953185&r2=953186&view=diff
==============================================================================
--- avro/trunk/lang/py/src/avro/io.py (original)
+++ avro/trunk/lang/py/src/avro/io.py Wed Jun  9 23:17:54 2010
@@ -68,7 +68,7 @@ class AvroTypeException(schema.AvroExcep
 class SchemaResolutionException(schema.AvroException):
   def __init__(self, fail_msg, writers_schema=None, readers_schema=None):
     if writers_schema: fail_msg += "\nWriter's Schema: %s" % writers_schema
-    if readers_schema: fail_msg += "\nReader's Schema: %s" % writers_schema
+    if readers_schema: fail_msg += "\nReader's Schema: %s" % readers_schema
     schema.AvroException.__init__(self, fail_msg)
 
 #
@@ -508,6 +508,10 @@ class DatumReader(object):
     """
     # read data
     index_of_symbol = decoder.read_int()
+    if index_of_symbol >= len(writers_schema.symbols):
+      fail_msg = "Can't access enum index %d for enum with %d symbols"\
+                 % (index_of_symbol, len(writers_schema.symbols))
+      raise SchemaResolutionException(fail_msg, writers_schema, readers_schema)
     read_symbol = writers_schema.symbols[index_of_symbol]
 
     # schema resolution
@@ -608,7 +612,7 @@ class DatumReader(object):
     index_of_schema = int(decoder.read_long())
     if index_of_schema >= len(writers_schema.schemas):
       fail_msg = "Can't access branch index %d for union with %d branches"\
-                 % (index_of_schema, writers_schema.schemas)
+                 % (index_of_schema, len(writers_schema.schemas))
       raise SchemaResolutionException(fail_msg, writers_schema, readers_schema)
     selected_writers_schema = writers_schema.schemas[index_of_schema]
     
@@ -617,6 +621,10 @@ class DatumReader(object):
 
   def skip_union(self, writers_schema, decoder):
     index_of_schema = int(decoder.read_long())
+    if index_of_schema >= len(writers_schema.schemas):
+      fail_msg = "Can't access branch index %d for union with %d branches"\
+                 % (index_of_schema, len(writers_schema.schemas))
+      raise SchemaResolutionException(fail_msg, writers_schema)
     return self.skip_data(writers_schema.schemas[index_of_schema], decoder)
 
   def read_record(self, writers_schema, readers_schema, decoder):



Mime
View raw message