From 2169ae215c86b3478be7e3ca552e3ef00c3091b2 Mon Sep 17 00:00:00 2001 From: ralmeida Date: Thu, 28 Oct 2021 14:42:03 +0100 Subject: [PATCH] Avoid ArrayIndexOutOfBoundsException on coordSeq when there are extra commands than specified in header --- .../com/wdtinc/mapbox_vector_tile/adapt/jts/MvtReader.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/wdtinc/mapbox_vector_tile/adapt/jts/MvtReader.java b/src/main/java/com/wdtinc/mapbox_vector_tile/adapt/jts/MvtReader.java index 3d6cee7..e1ecbf2 100644 --- a/src/main/java/com/wdtinc/mapbox_vector_tile/adapt/jts/MvtReader.java +++ b/src/main/java/com/wdtinc/mapbox_vector_tile/adapt/jts/MvtReader.java @@ -211,9 +211,13 @@ private static Geometry readPoints(GeometryFactory geomFactory, List ge // Guard: header data unsupported by geometry command buffer // (require header and at least 1 value * 2 params) - if(cmdLength * GeomCmd.MoveTo.getParamCount() + 1 > geomCmds.size()) { + int requiredgeomCmdsLength = cmdLength * GeomCmd.MoveTo.getParamCount() + 1; + if(requiredgeomCmdsLength > geomCmds.size()) { return null; } + if (requiredgeomCmdsLength < geomCmds.size()) { + geomCmds = geomCmds.subList(0, requiredgeomCmdsLength); // ignore extra commands... should it return null instead? + } final CoordinateSequence coordSeq = geomFactory.getCoordinateSequenceFactory().create(cmdLength, 2); int coordIndex = 0;