Преглед на файлове

Fixed #34026 -- Fixed WKBReader.read() crash on string input.

select-case преди 2 години
родител
ревизия
f3822d4ab0
променени са 2 файла, в които са добавени 11 реда и са изтрити 6 реда
  1. 4 1
      django/contrib/gis/geos/prototypes/io.py
  2. 7 5
      tests/gis_tests/geos_tests/test_io.py

+ 4 - 1
django/contrib/gis/geos/prototypes/io.py

@@ -169,8 +169,11 @@ class _WKBReader(IOBase):
         if isinstance(wkb, memoryview):
             wkb_s = bytes(wkb)
             return wkb_reader_read(self.ptr, wkb_s, len(wkb_s))
-        elif isinstance(wkb, (bytes, str)):
+        elif isinstance(wkb, bytes):
             return wkb_reader_read_hex(self.ptr, wkb, len(wkb))
+        elif isinstance(wkb, str):
+            wkb_s = wkb.encode()
+            return wkb_reader_read_hex(self.ptr, wkb_s, len(wkb_s))
         else:
             raise TypeError
 

+ 7 - 5
tests/gis_tests/geos_tests/test_io.py

@@ -56,15 +56,17 @@ class GEOSIOTest(SimpleTestCase):
         # Creating a WKBReader instance
         wkb_r = WKBReader()
 
-        hex = b"000000000140140000000000004037000000000000"
-        wkb = memoryview(binascii.a2b_hex(hex))
-        ref = GEOSGeometry(hex)
+        hex_bin = b"000000000140140000000000004037000000000000"
+        hex_str = "000000000140140000000000004037000000000000"
+        wkb = memoryview(binascii.a2b_hex(hex_bin))
+        ref = GEOSGeometry(hex_bin)
 
         # read() should return a GEOSGeometry on either a hex string or
         # a WKB buffer.
         g1 = wkb_r.read(wkb)
-        g2 = wkb_r.read(hex)
-        for geom in (g1, g2):
+        g2 = wkb_r.read(hex_bin)
+        g3 = wkb_r.read(hex_str)
+        for geom in (g1, g2, g3):
             self.assertEqual(ref, geom)
 
         bad_input = (1, 5.23, None, False)