[geos-commits] r3968 - in branches/3.3: src/io tests/unit/io

svn_geos at osgeo.org svn_geos at osgeo.org
Tue Dec 17 10:16:47 PST 2013


Author: strk
Date: 2013-12-17 10:16:47 -0800 (Tue, 17 Dec 2013)
New Revision: 3968

Modified:
   branches/3.3/src/io/WKBReader.cpp
   branches/3.3/tests/unit/io/WKBReaderTest.cpp
Log:
Throw a ParseException on missing chars from HEXWKB string (#675)

Includes testcase.

Modified: branches/3.3/src/io/WKBReader.cpp
===================================================================
--- branches/3.3/src/io/WKBReader.cpp	2013-12-10 10:03:38 UTC (rev 3967)
+++ branches/3.3/src/io/WKBReader.cpp	2013-12-17 18:16:47 UTC (rev 3968)
@@ -81,14 +81,15 @@
 	// setup input/output stream
 	stringstream os(ios_base::binary|ios_base::in|ios_base::out);
 
-	unsigned char high, low, result_high, result_low, value;
+	unsigned char result_high, result_low, value;
+	char high, low;
 
-	while(!is.eof())//readsome(&str[0], 2))
+	while( (high = is.get()) != char_traits<char>::eof() ) 
 	{
-		// get the high part of the byte
-		is >> high;
 		// geth the low part of the byte
-		is >> low;
+		low = is.get();
+		if ( low == char_traits<char>::eof() )
+		  throw ParseException("Premature end of HEX string");
 
 		switch (high)
 		{

Modified: branches/3.3/tests/unit/io/WKBReaderTest.cpp
===================================================================
--- branches/3.3/tests/unit/io/WKBReaderTest.cpp	2013-12-10 10:03:38 UTC (rev 3967)
+++ branches/3.3/tests/unit/io/WKBReaderTest.cpp	2013-12-17 18:16:47 UTC (rev 3968)
@@ -16,6 +16,7 @@
 #include <geos/geom/PrecisionModel.h>
 #include <geos/geom/GeometryFactory.h>
 #include <geos/geom/Geometry.h>
+#include <geos/util/GEOSException.h>
 // std
 #include <sstream>
 #include <string>
@@ -242,6 +243,25 @@
 
 	}
 
+  // 8 - Invalid HEXWKB for missing HEX char (#675)
+  template<>
+  template<>
+  void object::test<8>()
+  {         
+    std::stringstream hexwkb;
+    // NOTE: add a 0 to make valid
+    hexwkb << "01010000000000000000000000000000000000000";
+    //hexwkb << "0";
+    std::string err;
+    try {
+    GeomPtr gWKB_ndr(wkbreader.readHEX(hexwkb));
+    } catch (const geos::util::GEOSException& ex) {
+      err = ex.what();
+    }
+    ensure("Missing expected error", !err.empty());
+    ensure_equals(err, "ParseException: Premature end of HEX string");
+  }
 
+
 } // namespace tut
 



More information about the geos-commits mailing list