Fixed #34026 -- Fixed WKBReader.read() crash on string input.
This commit is contained in:
parent
2c7c22f94d
commit
f3822d4ab0
|
@ -169,8 +169,11 @@ class _WKBReader(IOBase):
|
||||||
if isinstance(wkb, memoryview):
|
if isinstance(wkb, memoryview):
|
||||||
wkb_s = bytes(wkb)
|
wkb_s = bytes(wkb)
|
||||||
return wkb_reader_read(self.ptr, wkb_s, len(wkb_s))
|
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))
|
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:
|
else:
|
||||||
raise TypeError
|
raise TypeError
|
||||||
|
|
||||||
|
|
|
@ -56,15 +56,17 @@ class GEOSIOTest(SimpleTestCase):
|
||||||
# Creating a WKBReader instance
|
# Creating a WKBReader instance
|
||||||
wkb_r = WKBReader()
|
wkb_r = WKBReader()
|
||||||
|
|
||||||
hex = b"000000000140140000000000004037000000000000"
|
hex_bin = b"000000000140140000000000004037000000000000"
|
||||||
wkb = memoryview(binascii.a2b_hex(hex))
|
hex_str = "000000000140140000000000004037000000000000"
|
||||||
ref = GEOSGeometry(hex)
|
wkb = memoryview(binascii.a2b_hex(hex_bin))
|
||||||
|
ref = GEOSGeometry(hex_bin)
|
||||||
|
|
||||||
# read() should return a GEOSGeometry on either a hex string or
|
# read() should return a GEOSGeometry on either a hex string or
|
||||||
# a WKB buffer.
|
# a WKB buffer.
|
||||||
g1 = wkb_r.read(wkb)
|
g1 = wkb_r.read(wkb)
|
||||||
g2 = wkb_r.read(hex)
|
g2 = wkb_r.read(hex_bin)
|
||||||
for geom in (g1, g2):
|
g3 = wkb_r.read(hex_str)
|
||||||
|
for geom in (g1, g2, g3):
|
||||||
self.assertEqual(ref, geom)
|
self.assertEqual(ref, geom)
|
||||||
|
|
||||||
bad_input = (1, 5.23, None, False)
|
bad_input = (1, 5.23, None, False)
|
||||||
|
|
Loading…
Reference in New Issue