[Django] #26378: Incorrect behavior in GenericIPAddressField with protocol='both', unpack_ipv4=False

12 views
Skip to first unread message

Django

unread,
Mar 18, 2016, 3:41:21 PM3/18/16
to django-...@googlegroups.com
#26378: Incorrect behavior in GenericIPAddressField with protocol='both',
unpack_ipv4=False
-------------------------------+--------------------
Reporter: bshen | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
https://dpaste.de/EMJa

Basically, IPv4-mapped IPv6 addresses in the CIDR block ::ffff:0.0.0.0/104
are validated as invalid when unpack_ipv4=False, yet is valid when the
first IPv4 octet is non-zero or when unpack_ipv4=True.

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

Django

unread,
Mar 18, 2016, 3:42:23 PM3/18/16
to django-...@googlegroups.com
#26378: Incorrect behavior in GenericIPAddressField with protocol='both',
unpack_ipv4=False
-------------------------------------+-------------------------------------

Reporter: bshen | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
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
-------------------------------------+-------------------------------------
Changes (by bshen):

* cc: bshen (added)
* needs_better_patch: => 0
* component: Uncategorized => Database layer (models, ORM)
* needs_tests: => 0
* easy: 0 => 1
* needs_docs: => 0


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

Django

unread,
Mar 18, 2016, 3:54:44 PM3/18/16
to django-...@googlegroups.com
#26378: Incorrect behavior in GenericIPAddressField with protocol='both',
unpack_ipv4=False
-------------------------------------+-------------------------------------

Reporter: bshen | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
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
-------------------------------------+-------------------------------------

Comment (by bshen):

Here's the paste dump in case the ticket goes older than the paste
expiration date:
{{{
# my.app.models
# Django==1.8.6
from django.db import models
class TestIPNoUnpack(models.Model):
ip = models.GenericIPAddressField(null=False, protocol='both',
unpack_ipv4=False)


class TestIPUnpack(models.Model):
ip = models.GenericIPAddressField(null=False, protocol='both',
unpack_ipv4=True)

> python manage.py shell
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
Type "copyright", "credits" or "license" for more information.

IPython 4.0.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.

In [1]: from my.app.models import TestIPNoUnpack, TestIPUnpack

In [2]: testipunpack = TestIPUnpack(ip='::ffff:0.0.0.0')

In [3]: testipunpack.clean_fields()

In [4]: testipunpack.ip
Out[4]: '0.0.0.0'

In [5]: testipnounpack = TestIPNoUnpack(ip='::ffff:0.0.0.0')

In [6]: testipnounpack.clean_fields()
---------------------------------------------------------------------------
ValidationError Traceback (most recent call
last)
<ipython-input-6-9a763f56e907> in <module>()
----> 1 testipnounpack.clean_fields()

.../lib/python2.7/site-packages/django/db/models/base.pyc in
clean_fields(self, exclude)
1194
1195 if errors:
-> 1196 raise ValidationError(errors)
1197
1198 @classmethod

ValidationError: {'ip': [u'Enter a valid IPv4 or IPv6 address.']}

In [7]: testipnounpack2 = TestIPNoUnpack(ip='::ffff:0.255.255.255')

In [8]: testipnounpack2.clean_fields()
---------------------------------------------------------------------------
ValidationError Traceback (most recent call
last)
<ipython-input-8-e228d0855286> in <module>()
----> 1 testipnounpack2.clean_fields()

.../lib/python2.7/site-packages/django/db/models/base.pyc in
clean_fields(self, exclude)
1194
1195 if errors:
-> 1196 raise ValidationError(errors)
1197
1198 @classmethod

ValidationError: {'ip': [u'Enter a valid IPv4 or IPv6 address.']}

In [9]: testipnounpack3 = TestIPNoUnpack(ip='::ffff:1.0.0.0')

In [10]: testipnounpack3.clean_fields()

In [11]: testipnounpack3.ip
Out[11]: '::ffff:1.0.0.0'

}}}

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

Django

unread,
Mar 18, 2016, 8:02:49 PM3/18/16
to django-...@googlegroups.com
#26378: Incorrect behavior in GenericIPAddressField with protocol='both',
unpack_ipv4=False
-------------------------------------+-------------------------------------

Reporter: bshen | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.8
(models, ORM) |
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 timgraham:

Old description:

> https://dpaste.de/EMJa
>
> Basically, IPv4-mapped IPv6 addresses in the CIDR block
> ::ffff:0.0.0.0/104 are validated as invalid when unpack_ipv4=False, yet
> is valid when the first IPv4 octet is non-zero or when unpack_ipv4=True.

New description:

Basically, IPv4-mapped IPv6 addresses in the CIDR block ::ffff:0.0.0.0/104
are validated as invalid when unpack_ipv4=False, yet is valid when the
first IPv4 octet is non-zero or when unpack_ipv4=True.

{{{ #!python

In [3]: testipunpack.clean_fields()

In [10]: testipnounpack3.clean_fields()

}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/26378#comment:3>

Django

unread,
Mar 20, 2016, 12:38:06 PM3/20/16
to django-...@googlegroups.com
#26378: Incorrect behavior in GenericIPAddressField with protocol='both',
unpack_ipv4=False
-------------------------------------+-------------------------------------
Reporter: bshen | Owner:
| AmineYaiche
Type: Bug | Status: assigned

Component: Database layer | Version: 1.8
(models, ORM) |
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 AmineYaiche):

* owner: nobody => AmineYaiche
* status: new => assigned
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/26378#comment:4>

Django

unread,
Mar 20, 2016, 3:59:45 PM3/20/16
to django-...@googlegroups.com
#26378: Incorrect behavior in GenericIPAddressField with protocol='both',
unpack_ipv4=False
-------------------------------------+-------------------------------------
Reporter: bshen | Owner:
| AmineYaiche
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
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 AmineYaiche):

* Attachment "26378.diff" added.

Django

unread,
Mar 21, 2016, 8:25:36 AM3/21/16
to django-...@googlegroups.com
#26378: Incorrect behavior in GenericIPAddressField with protocol='both',
unpack_ipv4=False
-------------------------------------+-------------------------------------
Reporter: bshen | Owner:
| AmineYaiche
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/6316 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/26378#comment:5>

Django

unread,
Mar 21, 2016, 2:08:42 PM3/21/16
to django-...@googlegroups.com
#26378: Incorrect behavior in GenericIPAddressField with protocol='both',
unpack_ipv4=False
-------------------------------------+-------------------------------------
Reporter: bshen | Owner:
| AmineYaiche
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by timgraham:

Old description:

> Basically, IPv4-mapped IPv6 addresses in the CIDR block


> ::ffff:0.0.0.0/104 are validated as invalid when unpack_ipv4=False, yet
> is valid when the first IPv4 octet is non-zero or when unpack_ipv4=True.
>

New description:

Basically, IPv4-mapped IPv6 addresses in the CIDR block ::ffff:0.0.0.0/104
are validated as invalid when unpack_ipv4=False, yet is valid when the
first IPv4 octet is non-zero or when unpack_ipv4=True.

{{{ #!python


# my.app.models
# Django==1.8.6
from django.db import models

class TestIPNoUnpack(models.Model):
ip = models.GenericIPAddressField(null=False, protocol='both',
unpack_ipv4=False)


class TestIPUnpack(models.Model):
ip = models.GenericIPAddressField(null=False, protocol='both',
unpack_ipv4=True)

> python manage.py shell

In [1]: from my.app.models import TestIPNoUnpack, TestIPUnpack

In [2]: testipunpack = TestIPUnpack(ip='::ffff:0.0.0.0')

In [3]: testipunpack.clean_fields()

In [4]: testipunpack.ip
Out[4]: '0.0.0.0'

In [5]: testipnounpack = TestIPNoUnpack(ip='::ffff:0.0.0.0')

In [6]: testipnounpack.clean_fields()

ValidationError: {'ip': [u'Enter a valid IPv4 or IPv6 address.']}

In [7]: testipnounpack2 = TestIPNoUnpack(ip='::ffff:0.255.255.255')

In [8]: testipnounpack2.clean_fields()

ValidationError: {'ip': [u'Enter a valid IPv4 or IPv6 address.']}

In [9]: testipnounpack3 = TestIPNoUnpack(ip='::ffff:1.0.0.0')

In [10]: testipnounpack3.clean_fields()

In [11]: testipnounpack3.ip
Out[11]: '::ffff:1.0.0.0'

}}}

--

--
Ticket URL: <https://code.djangoproject.com/ticket/26378#comment:6>

Django

unread,
Mar 21, 2016, 3:06:36 PM3/21/16
to django-...@googlegroups.com
#26378: Incorrect behavior in GenericIPAddressField with protocol='both',
unpack_ipv4=False
-------------------------------------+-------------------------------------
Reporter: bshen | Owner:
| AmineYaiche
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by bshen):

Is this the actual desired behavior? I don't think we want to have mixed
IPv4 and IPv6 representation be invalid when unpack_ipv4 is False. Mixed
IPv4 and IPv6 is still valid IPv6. In fact, this would probably break
existing code written by others that depends on this functionality where
the first IPv4 octet is not 0.

Furthermore, it appears that root cause of the inconsistency is not
addressed, but rather a whole class of valid IPv6 addresses is now marked
invalid.

--
Ticket URL: <https://code.djangoproject.com/ticket/26378#comment:7>

Django

unread,
Mar 21, 2016, 5:27:41 PM3/21/16
to django-...@googlegroups.com
#26378: Incorrect behavior in GenericIPAddressField with protocol='both',
unpack_ipv4=False
-------------------------------------+-------------------------------------
Reporter: bshen | Owner:
| AmineYaiche
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by AmineYaiche):

You are completely right. My apologies for the inconvenience. I was
looking at the wrong problem.

--
Ticket URL: <https://code.djangoproject.com/ticket/26378#comment:8>

Django

unread,
Mar 21, 2016, 5:58:09 PM3/21/16
to django-...@googlegroups.com
#26378: Incorrect behavior in GenericIPAddressField with protocol='both',
unpack_ipv4=False
-------------------------------------+-------------------------------------
Reporter: bshen | Owner:
| AmineYaiche
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by AmineYaiche):

* Attachment "26378.1.diff" added.

Django

unread,
Mar 21, 2016, 6:17:43 PM3/21/16
to django-...@googlegroups.com
#26378: Incorrect behavior in GenericIPAddressField with protocol='both',
unpack_ipv4=False
-------------------------------------+-------------------------------------
Reporter: bshen | Owner:
| AmineYaiche
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by bshen):

This looks like the correct fix. Thanks for responding and fixing it
quickly!

--
Ticket URL: <https://code.djangoproject.com/ticket/26378#comment:9>

Django

unread,
Mar 21, 2016, 7:31:00 PM3/21/16
to django-...@googlegroups.com
#26378: Incorrect behavior in GenericIPAddressField with protocol='both',
unpack_ipv4=False
-------------------------------------+-------------------------------------
Reporter: bshen | Owner:
| AmineYaiche
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

Hi Amine, just wanted to mention for future reference that you don't need
to attach a patch here when you also send a pull request.

--
Ticket URL: <https://code.djangoproject.com/ticket/26378#comment:10>

Django

unread,
Mar 23, 2016, 8:20:11 AM3/23/16
to django-...@googlegroups.com
#26378: Allowed a left byte of zero in mixed IPv4/IPv6 validation

-------------------------------------+-------------------------------------
Reporter: bshen | Owner:
| AmineYaiche
Type: Bug | Status: assigned
Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

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

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/26378#comment:11>

Django

unread,
Mar 23, 2016, 8:21:23 AM3/23/16
to django-...@googlegroups.com
#26378: Allowed a left byte of zero in mixed IPv4/IPv6 validation
-------------------------------------+-------------------------------------
Reporter: bshen | Owner:
| AmineYaiche
Type: Bug | Status: closed

Component: Database layer | Version: 1.8
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"32c8e43ef1e859fa55af2f470a2a1120f51afabe" 32c8e43e]:
{{{
#!CommitTicketReference repository=""
revision="32c8e43ef1e859fa55af2f470a2a1120f51afabe"
Fixed #26378 -- Allowed a left byte of zero in mixed IPv4/IPv6 validation.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26378#comment:12>

Reply all
Reply to author
Forward
0 new messages