[geos-commits] r3965 - in branches/3.4: . src/io tests/unit/io

svn_geos at osgeo.org svn_geos at osgeo.org
Tue Dec 10 01:12:22 PST 2013


Author: strk
Date: 2013-12-10 01:12:22 -0800 (Tue, 10 Dec 2013)
New Revision: 3965

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

Includes testcase.

Modified: branches/3.4/NEWS
===================================================================
--- branches/3.4/NEWS	2013-12-10 09:11:09 UTC (rev 3964)
+++ branches/3.4/NEWS	2013-12-10 09:12:22 UTC (rev 3965)
@@ -3,6 +3,7 @@
 
 - Bug fixes / improvements
  - Fix build on HP-UX 11.23 (#664)
+ - Throw a ParseException on missing chars from HEXWKB string (#675)
 
 Changes in 3.4.2
 2013-08-25

Modified: branches/3.4/src/io/WKBReader.cpp
===================================================================
--- branches/3.4/src/io/WKBReader.cpp	2013-12-10 09:11:09 UTC (rev 3964)
+++ branches/3.4/src/io/WKBReader.cpp	2013-12-10 09:12:22 UTC (rev 3965)
@@ -80,14 +80,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.4/tests/unit/io/WKBReaderTest.cpp
===================================================================
--- branches/3.4/tests/unit/io/WKBReaderTest.cpp	2013-12-10 09:11:09 UTC (rev 3964)
+++ branches/3.4/tests/unit/io/WKBReaderTest.cpp	2013-12-10 09:12:22 UTC (rev 3965)
@@ -15,6 +15,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>
@@ -241,6 +242,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