[geos-commits] [SCM] GEOS branch main updated. a2525885ffe40a641bb1521c2cdb013f8a64ba34
git at osgeo.org
git at osgeo.org
Wed Oct 28 08:41:39 PDT 2026
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".
The branch, main has been updated
via a2525885ffe40a641bb1521c2cdb013f8a64ba34 (commit)
from a9752091be7ca35f0ffd94c37ef77530ff3dc194 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit a2525885ffe40a641bb1521c2cdb013f8a64ba34
Author: Daniel Baston <dbaston at gmail.com>
Date: Wed Oct 28 11:39:25 2026 -0400
WKBWriter: preserve includeSRID setting after failed write (#1578)
Resolves https://github.com/libgeos/geos/issues/1567
diff --git a/src/io/WKBWriter.cpp b/src/io/WKBWriter.cpp
index 95c64b044..c71fd1031 100644
--- a/src/io/WKBWriter.cpp
+++ b/src/io/WKBWriter.cpp
@@ -186,9 +186,14 @@ WKBWriter::writeCompoundCurve(const CompoundCurve& g)
auto orig_includeSRID = includeSRID;
includeSRID = false;
- for (std::size_t i = 0; i < g.getNumCurves(); i++) {
- const SimpleCurve& section = *g.getCurveN(i);
- writeSimpleCurve(section);
+ try {
+ for (std::size_t i = 0; i < g.getNumCurves(); i++) {
+ const SimpleCurve& section = *g.getCurveN(i);
+ writeSimpleCurve(section);
+ }
+ } catch (...) {
+ includeSRID = orig_includeSRID;
+ throw;
}
includeSRID = orig_includeSRID;
@@ -273,12 +278,19 @@ WKBWriter::writeGeometryCollection(const GeometryCollection& g)
includeSRID = false;
assert(outStream);
- for(std::size_t i = 0; i < ngeoms; i++) {
- const Geometry* elem = g.getGeometryN(i);
- assert(elem);
- write(*elem, *outStream);
+ try {
+ for(std::size_t i = 0; i < ngeoms; i++) {
+ const Geometry* elem = g.getGeometryN(i);
+ assert(elem);
+
+ write(*elem, *outStream);
+ }
+ } catch (...) {
+ includeSRID = orig_includeSRID;
+ throw;
}
+
includeSRID = orig_includeSRID;
}
diff --git a/tests/unit/io/WKBWriterTest.cpp b/tests/unit/io/WKBWriterTest.cpp
index 21387fe6c..71ef08ac3 100644
--- a/tests/unit/io/WKBWriterTest.cpp
+++ b/tests/unit/io/WKBWriterTest.cpp
@@ -3,6 +3,7 @@
// tut
#include <tut/tut.hpp>
+#include <tut/tut_macros.hpp>
// geos
#include <geos/io/WKBReader.h>
#include <geos/io/WKBWriter.h>
@@ -478,6 +479,39 @@ void object::test<19>
"010A0000200E1600000200000001090000000200000001080000000500000000000000000000000000000000000000000000000000004000000000000000000000000000000040000000000000F03F00000000000000400000000000000840000000000000104000000000000008400102000000040000000000000000001040000000000000084000000000000010400000000000001440000000000000F03F000000000000104000000000000000000000000000000000010800000005000000333333333333FB3F000000000000F03F666666666666F63F9A9999999999D93F9A9999999999F93F9A9999999999D93F9A9999999999F93F000000000000E03F333333333333FB3F000000000000F03F");
}
+// includeSRID is kept when writing a collection or a compound curve fails
+// because the output stream throws
+template<>
+template<>
+void object::test<20>
+() {
+ // accepts 20 bytes, then fails
+ struct FixedBuf : std::streambuf {
+ char data[20]{};
+ FixedBuf() { setp(data, data + sizeof data); }
+ };
+
+ geos::io::WKBWriter writer(2, geos::io::ByteOrderValues::ENDIAN_LITTLE, true);
+ auto point = wktreader.read("POINT (1 2)");
+ point->setSRID(4326);
+
+ for (const char *wkt: {
+ "GEOMETRYCOLLECTION (POINT (1 2), LINESTRING (0 0, 1 1))",
+ "COMPOUNDCURVE (CIRCULARSTRING (0 0, 1 1, 2 0), (2 0, 3 0))"
+ }) {
+ auto geom = wktreader.read(wkt);
+ geom->setSRID(3857);
+
+ FixedBuf buf;
+ std::ostream os(&buf);
+ os.exceptions(std::ios::badbit | std::ios::failbit);
+ ensure_THROW(writer.write(*geom, os), std::ios_base::failure);
+ ensure("getIncludeSRID() should be set after writing " + std::string(wkt), writer.getIncludeSRID());
+ std::stringstream out;
+ writer.writeHEX(*point, out);
+ ensure_equals(wkt, out.str(), "0101000020E6100000000000000000F03F0000000000000040");
+ }
+}
} // namespace tut
-----------------------------------------------------------------------
Summary of changes:
src/io/WKBWriter.cpp | 26 +++++++++++++++++++-------
tests/unit/io/WKBWriterTest.cpp | 34 ++++++++++++++++++++++++++++++++++
2 files changed, 53 insertions(+), 7 deletions(-)
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list