This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: UUID versions are not validated to lie in the documented range
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6, Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: uuid returns version more than 5
View: 34732
Assigned To: Nosy List: David MacIver, berker.peksag, conqp, xtreak
Priority: normal Keywords:

Created on 2017-11-06 11:31 by David MacIver, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg305636 - (view) Author: David MacIver (David MacIver) * Date: 2017-11-06 11:31
The documentation for the UUID module says the UUID.version field is "The UUID version number (1 through 5, meaningful only when the variant is RFC_4122)".

However, the UUID constructor doesn't actually validate that the version lies in that range if you don't pass a version to the constructor and, as a result, this isn't actually true - the version number can be anything between 0 and 15.

For an example consider the following:

>>> from uuid import UUID
>>> u = UUID(int=1133377179260751706062848)
>>> u.variant
'specified in RFC 4122'
>>> u.version
15

I have only actually run this example on Python 3.6, but inspection of the code suggests that it's been like this since its introduction.
msg305646 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017-11-06 15:45
What do you propose? Raise an exception in the constructor if the version is not in the range 1..5? Or just modify the variant value?
msg325753 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-09-19 12:39
Related issue : https://bugs.python.org/issue34732 . It has a PR to raise an exception in the constructor and it seems to cause tests to fail at https://ci.appveyor.com/project/python/cpython/build/3.8build22654

Thanks
msg325758 - (view) Author: Richard Neumann (conqp) * Date: 2018-09-19 13:06
@xtreak Indeed. It fails on _windll_getnode().

======================================================================
ERROR: test_windll_getnode (test.test_uuid.TestInternalsWithoutExtModule)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\projects\cpython\lib\test\test_uuid.py", line 748, in test_windll_getnode
    node = self.uuid._windll_getnode()
  File "C:\projects\cpython\lib\uuid.py", line 659, in _windll_getnode
    return UUID(bytes=bytes_(_buffer.raw)).node
  File "C:\projects\cpython\lib\uuid.py", line 208, in __init__
    raise ValueError('illegal version number')
ValueError: illegal version number
----------------------------------------------------------------------

Apparently on Windows systems, there are UUIDs of type RFC_4122 being used which have versions not in 1..5, which actually makes them non-RFC 4122 compliant.
Unfortunately I cannot investigate this further, since I do not have a windows machine available right now.
msg325809 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2018-09-19 22:33
Issue 34732 is actually a duplicate of this issue, but I'm going to close this one instead since the former has already two open pull requests. Thanks for the report!
History
Date User Action Args
2022-04-11 14:58:54adminsetgithub: 76139
2018-09-19 22:33:43berker.peksagsetstatus: open -> closed

superseder: uuid returns version more than 5
type: behavior

nosy: + berker.peksag
messages: + msg325809
resolution: duplicate
stage: resolved
2018-09-19 13:42:54vstinnersetnosy: - vstinner
2018-09-19 13:06:25conqpsetnosy: + conqp
messages: + msg325758
2018-09-19 12:39:35xtreaksetnosy: + xtreak
messages: + msg325753
2017-11-06 15:45:00vstinnersetnosy: + vstinner
messages: + msg305646
2017-11-06 11:32:04David MacIversettitle: UUID -> UUID versions are not validated to lie in the documented range
2017-11-06 11:31:27David MacIvercreate