This is an automated email from the ASF dual-hosted git repository.
jiayu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sedona.git
The following commit(s) were added to refs/heads/master by this push:
new 6bc52c38ca [GH-2036] update more robust instream count for Geography
decode (#2305)
6bc52c38ca is described below
commit 6bc52c38ca1726c7a0c679e4d1086a312a2eaabd
Author: Zhuocheng Shang <[email protected]>
AuthorDate: Wed Aug 20 21:17:24 2025 -0700
[GH-2036] update more robust instream count for Geography decode (#2305)
* update to more robust check instream count
* empty commit to retrigger ci
---
.../common/S2Geography/GeographyCollection.java | 29 ++++++++++++--------
.../common/S2Geography/PolylineGeography.java | 32 ++++++++++++----------
2 files changed, 35 insertions(+), 26 deletions(-)
diff --git
a/common/src/main/java/org/apache/sedona/common/S2Geography/GeographyCollection.java
b/common/src/main/java/org/apache/sedona/common/S2Geography/GeographyCollection.java
index 71e9f84624..85e23c935e 100644
---
a/common/src/main/java/org/apache/sedona/common/S2Geography/GeographyCollection.java
+++
b/common/src/main/java/org/apache/sedona/common/S2Geography/GeographyCollection.java
@@ -135,20 +135,25 @@ public class GeographyCollection extends Geography {
// Skip any covering data
tag.skipCovering(in);
- // 3) Ensure we have at least 4 bytes for the count
- if (in.available() < Integer.BYTES) {
- throw new IOException("GeographyCollection.decodeTagged error:
insufficient header bytes");
- }
+ try {
+ int count = in.readInt();
+ if (count < 0) {
+ throw new IOException("GeographyCollection.decodeTagged error:
negative count: " + count);
+ }
+
+ for (int i = 0; i < count; i++) {
+ tag = EncodeTag.decode(in);
+ // avoid creating new stream, directly call S2Geography.decode
+ Geography feature = Geography.decode(in, tag);
+ geo.features.add(feature);
+ }
+ geo.countShapes();
- // Read feature count
- int n = in.readInt();
- for (int i = 0; i < n; i++) {
- tag = EncodeTag.decode(in);
- // avoid creating new stream, directly call S2Geography.decode
- Geography feature = Geography.decode(in, tag);
- geo.features.add(feature);
+ } catch (EOFException e) {
+ throw new IOException(
+ "GeographyCollection.decodeTagged error: insufficient data to decode
all parts of the geography.",
+ e);
}
- geo.countShapes();
return geo;
}
diff --git
a/common/src/main/java/org/apache/sedona/common/S2Geography/PolylineGeography.java
b/common/src/main/java/org/apache/sedona/common/S2Geography/PolylineGeography.java
index a8bb1638f8..6e71072889 100644
---
a/common/src/main/java/org/apache/sedona/common/S2Geography/PolylineGeography.java
+++
b/common/src/main/java/org/apache/sedona/common/S2Geography/PolylineGeography.java
@@ -138,22 +138,26 @@ public class PolylineGeography extends Geography {
// 2) Skip past any covering cell-IDs written by encodeTagged
tag.skipCovering(in);
- // 3) Ensure we have at least 4 bytes for the count
- if (in.available() < Integer.BYTES) {
- throw new IOException("PolylineGeography.decodeTagged error:
insufficient header bytes");
- }
-
- // 5) Read the number of polylines (4-byte)
- int count = in.readInt();
+ // 3) Read the number of polylines (4-byte)
+ try {
+ int count = in.readInt();
+ if (count < 0) {
+ throw new IOException("PolylineGeography.decodeTagged error: negative
count: " + count);
+ }
+ if (tag.getKind() == GeographyKind.SINGLEPOLYLINE) {
+ return new SinglePolylineGeography(S2Polyline.decode(in));
+ }
- if (tag.getKind() == GeographyKind.SINGLEPOLYLINE) {
- return new SinglePolylineGeography(S2Polyline.decode(in));
- }
+ // 4) For each polyline, read its block and let
S2Polyline.decode(InputStream) do the rest
+ for (int i = 0; i < count; i++) {
+ S2Polyline pl = S2Polyline.decode(in);
+ geo.polylines.add(pl);
+ }
- // 6) For each polyline, read its block and let
S2Polyline.decode(InputStream) do the rest
- for (int i = 0; i < count; i++) {
- S2Polyline pl = S2Polyline.decode(in);
- geo.polylines.add(pl);
+ } catch (EOFException e) {
+ throw new IOException(
+ "PolylineGeography.decodeTagged error: insufficient data to decode
all parts of the geography.",
+ e);
}
return geo;
}