[geos-commits] r3964 - in trunk: src/io tests/unit/io
svn_geos at osgeo.org
svn_geos at osgeo.org
Tue Dec 10 01:11:09 PST 2013
Author: strk
Date: 2013-12-10 01:11:09 -0800 (Tue, 10 Dec 2013)
New Revision: 3964
Modified:
trunk/src/io/WKBReader.cpp
trunk/tests/unit/io/WKBReaderTest.cpp
Log:
Throw a ParseException on missing chars from HEXWKB string (#675)
Includes testcase.
Modified: trunk/src/io/WKBReader.cpp
===================================================================
--- trunk/src/io/WKBReader.cpp 2013-11-19 17:28:47 UTC (rev 3963)
+++ trunk/src/io/WKBReader.cpp 2013-12-10 09:11:09 UTC (rev 3964)
@@ -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: trunk/tests/unit/io/WKBReaderTest.cpp
===================================================================
--- trunk/tests/unit/io/WKBReaderTest.cpp 2013-11-19 17:28:47 UTC (rev 3963)
+++ trunk/tests/unit/io/WKBReaderTest.cpp 2013-12-10 09:11:09 UTC (rev 3964)
@@ -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