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

This commit is contained in:
select-case 2022-09-24 21:46:08 +05:30 committed by GitHub
parent 2c7c22f94d
commit f3822d4ab0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View File

@ -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

View File

@ -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)