UnmarshalTWKB decodes a huge element count as an empty geometry

Abierto Apto para principiantes
#725 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
go
Área
backend

Línea de trabajo

Empieza con UnmarshalTWKB y con las cuatro funciones nextMultiPoint, nextMultiLineString, nextMultiPolygon y nextGeometryCollection, que leen el contador como uint64 y recorren en bucle con int(count). Copia la comparación de bytes restantes usada en parsePointArray y parseIDList en esas cuatro funciones, antes de sus bucles. Luego amplía TestUnmarshalTWKBHugeCount con un caso para cada tipo, usando las entradas hexadecimales del issue, y confirma que devuelven un error.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug

UnmarshalTWKB returns an empty geometry rather than an error when a MultiPoint, MultiLineString, MultiPolygon or GeometryCollection declares 2^63 or more elements. This reproduces on master at a5aec8d on a 64-bit platform.

Input Result
0400ffffffffffffffffff01 MULTIPOINT EMPTY
0500ffffffffffffffffff01 MULTILINESTRING EMPTY
0600ffffffffffffffffff01 MULTIPOLYGON EMPTY
0700ffffffffffffffffff01 GEOMETRYCOLLECTION EMPTY
0700ffffffffffffffffff0101000204 GEOMETRYCOLLECTION EMPTY

Each input is a type byte, a metadata header without any flags set, and the varint for 2^64-1. The last input has a POINT(1 2) after the count, which is ignored.

Cause

The count is read as a uint64. nextMultiPoint, nextMultiLineString, nextMultiPolygon and nextGeometryCollection then loop with for i := 0; i < int(count); i++. A count of 2^63 or more converts to a negative int, so the loop body never runs. A count of 2^63-1 is rejected, because the first element can't be read from the remaining input.

parsePointArray and parseIDList compare the count with the remaining buffer size before narrowing it, and TestUnmarshalTWKBHugeCount covers both. That is why a huge point count in a LineString or a polygon ring is rejected, and why the inputs above are rejected when the ID list flag is set.

Likely fix

Make the same comparison in the four functions before the loop. Every element takes at least one byte, so a count larger than the number of remaining bytes can't be valid. TestUnmarshalTWKBHugeCount can then get a case for each of the four types.

Lenguaje dominante
Go
Estrellas
176
Forks
27
Merge medio
1 d 14 h
PR fusionados (30 d)
4

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de peterstace/simplefeatures

Todos los issues de peterstace/simplefeatures

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.