UnmarshalTWKB decodes a huge element count as an empty geometry

Đang mở Phù hợp với người mới
#725 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu với UnmarshalTWKB và bốn hàm nextMultiPoint, nextMultiLineString, nextMultiPolygon và nextGeometryCollection, các hàm này đọc số đếm dưới dạng uint64 và lặp theo int(count). Sao chép phép so sánh số byte còn lại đang dùng trong parsePointArray và parseIDList vào bốn hàm đó, trước các vòng lặp của chúng. Sau đó, mở rộng TestUnmarshalTWKBHugeCount với một trường hợp cho mỗi kiểu, dùng các đầu vào hex trong issue, và xác nhận chúng trả về lỗi.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Go
Star
176
Fork
27
Merge trung bình
1 ngày 14 giờ
Pull request đã merge (30 ngày)
4

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của peterstace/simplefeatures

Tất cả issue của peterstace/simplefeatures

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.