[Django] #34026: WKBReader Type Error

5 views
Skip to first unread message

Django

unread,
Sep 21, 2022, 6:22:18 AM9/21/22
to django-...@googlegroups.com
#34026: WKBReader Type Error
----------------------------------------+------------------------
Reporter: Benoît Vinot | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 4.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
----------------------------------------+------------------------
Hi,

There is a potential type error in the implementation of the `read` method
of the `WKBReader` class in `contrib.gis`. Here is a small example to
create the problem:


{{{
from django.contrib.gis.geos.prototypes.io import _WKBReader
wkb='0101000020E6100000C07DD40B0FA8F5BF8794C5DD53DD4740'
_WKBReader().read(wkb)
}}}

This code works fine:

{{{
from django.contrib.gis.geos.prototypes.io import _WKBReader
wkb='0101000020E6100000C07DD40B0FA8F5BF8794C5DD53DD4740'
_WKBReader().read(wkb.encode())
}}}

I suggest to replace the current implementation of this method by:

{{{
def read(self, wkb):
"Return a _pointer_ to C GEOS Geometry object from the given WKB."
if isinstance(wkb, memoryview):
wkb_s = bytes(wkb)
return wkb_reader_read(self.ptr, wkb_s, len(wkb_s))
elif isinstance(wkb, bytes):
return wkb_reader_read_hex(self.ptr, wkb, len(wkb))
elif isinstance(wkb, str):
wkb_s = wkb.encode() # <------------------- Ensure bytes
return wkb_reader_read_hex(self.ptr, wkb_s, len(wkb_s))
else:
raise TypeError
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34026>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Sep 21, 2022, 6:23:17 AM9/21/22
to django-...@googlegroups.com
#34026: WKBReader Type Error
------------------------------+--------------------------------------

Reporter: Benoît Vinot | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 4.1
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
------------------------------+--------------------------------------
Description changed by Benoît Vinot:

Old description:

New description:

Hi,

There is a potential type error in the implementation of the `read` method
of the `WKBReader` class in `contrib.gis`. Here is a small example to
create the problem:


{{{
from django.contrib.gis.geos.prototypes.io import _WKBReader
wkb='0101000020E6100000C07DD40B0FA8F5BF8794C5DD53DD4740' # <-- string
_WKBReader().read(wkb)
}}}

This code works fine:

{{{
from django.contrib.gis.geos.prototypes.io import _WKBReader
wkb='0101000020E6100000C07DD40B0FA8F5BF8794C5DD53DD4740'

_WKBReader().read(wkb.encode()) # <--- Converted into bytes
}}}

I suggest replacing the current implementation of this method by:

{{{
def read(self, wkb):
"Return a _pointer_ to C GEOS Geometry object from the given WKB."
if isinstance(wkb, memoryview):
wkb_s = bytes(wkb)
return wkb_reader_read(self.ptr, wkb_s, len(wkb_s))
elif isinstance(wkb, bytes):
return wkb_reader_read_hex(self.ptr, wkb, len(wkb))
elif isinstance(wkb, str):
wkb_s = wkb.encode() # <------------------- Ensure bytes
return wkb_reader_read_hex(self.ptr, wkb_s, len(wkb_s))
else:
raise TypeError
}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/34026#comment:1>

Django

unread,
Sep 21, 2022, 7:18:04 AM9/21/22
to django-...@googlegroups.com
#34026: WKBReader Type Error
------------------------------+------------------------------------

Reporter: Benoît Vinot | Owner: nobody
Type: Bug | Status: new
Component: GIS | Version: 4.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* stage: Unreviewed => Accepted


Comment:

Agreed, it doesn't work as
[https://docs.djangoproject.com/en/stable/ref/contrib/gis/geos/#django.contrib.gis.geos.WKBReader
documented].

--
Ticket URL: <https://code.djangoproject.com/ticket/34026#comment:2>

Reply all
Reply to author
Forward
0 new messages