Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix element number estimation when parsing WKB of GEOMETRYCOLLECTION containing empty geometries #905

Conversation

Kontinuation
Copy link
Contributor

WKBReader will raise ParseException when parsing WKB of GeometryCollection containing multiple empty geometries, such as GEOMETRYCOLLECTION(LINESTRING EMPTY, MULTIPOINT EMPTY). The following code reproduces this problem:

WKTReader wktReader = new WKTReader();
WKBWriter wkbWriter = new WKBWriter();
WKBReader wkbReader = new WKBReader();
Geometry geom = wktReader.read("GEOMETRYCOLLECTION(LINESTRING EMPTY, MULTIPOINT EMPTY)");
byte[] wkb = wkbWriter.write(geom);
wkbReader.read(wkb);

Which yields:

Exception in thread "main" org.locationtech.jts.io.ParseException: null value is too large
	at org.locationtech.jts.io.WKBReader.readNumField(WKBReader.java:198)
	at org.locationtech.jts.io.WKBReader.readGeometryCollection(WKBReader.java:385)
	at org.locationtech.jts.io.WKBReader.readGeometry(WKBReader.java:279)
	at org.locationtech.jts.io.WKBReader.read(WKBReader.java:191)
	at org.locationtech.jts.io.WKBReader.read(WKBReader.java:159)

This PR fixes this problem by estimating the number of geometries in GeometryCollection in a more conservative manner: the minimal length of a WKB geometry is 9 (1 byte order + 4 WKT type + 4 length), we estimate the number of geometries by dividing the length of WKB buffer by 8 instead of 16.

…containing empty geometries

Signed-off-by: Kristin Cowalcijk <morisama@yeah.net>
@dr-jts
Copy link
Contributor

dr-jts commented Sep 14, 2022

Thanks, good catch!

@dr-jts dr-jts merged commit c5b9d9c into locationtech:master Sep 14, 2022
@nenadzdravkovic-tomtom
Copy link

Hi @dr-jts , if I may kindly ask - are there any plans to make a release with this fix in near future? I don't see any fixed date on https://github.com/locationtech/jts/milestones.
Thanks!

@dr-jts
Copy link
Contributor

dr-jts commented Jun 15, 2023

Hi @dr-jts , if I may kindly ask - are there any plans to make a release with this fix in near future?

No firm release date, but will try and get one out over the summer.

@jodygarnett jodygarnett added this to the 1.20.0 milestone Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants