Skip to content

Conversation

@miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Apr 20, 2018

Fix clang ubsan (undefined behavior sanitizer) warnings in dictobject.c by
adjusting how the internal struct _dictkeysobject shared keys structure is
declared.

This remains ABI compatible. We get rid of the union at the end of the
struct being used for conveinence to avoid typecasting in favor of char[]
variable length array at the end of a struct. This is known to clang to be
used for variable sized objects and will not cause an undefined behavior
problem. Similarly, char arrays do not have strict aliasing undefined
behavior when cast.

PEP-007 does not currently list variable length arrays (VLAs) as allowed
in our subset of C99. If this turns out to be a problem, the fix to this is
to change the char dk_indices[] into dk_indices[1] and restore the
three size computation subtractions this change removes:
- Py_MEMBER_SIZE(PyDictKeysObject, dk_indices)

If this works as is I'll make a separate PR to update PEP-007.
(cherry picked from commit 397f1b2)

Co-authored-by: Gregory P. Smith [email protected]

https://bugs.python.org/issue33312

…6537)

Fix clang ubsan (undefined behavior sanitizer) warnings in dictobject.c by
adjusting how the internal struct _dictkeysobject shared keys structure is
declared.

This remains ABI compatible.  We get rid of the union at the end of the
struct being used for conveinence to avoid typecasting in favor of char[]
variable length array at the end of a struct. This is known to clang to be
used for variable sized objects and will not cause an undefined behavior
problem.  Similarly, char arrays do not have strict aliasing undefined
behavior when cast.

PEP-007 does not currently list variable length arrays (VLAs) as allowed
in our subset of C99.  If this turns out to be a problem, the fix to this is
to change the char `dk_indices[]` into `dk_indices[1]` and restore the
three size computation subtractions this change removes:
  `- Py_MEMBER_SIZE(PyDictKeysObject, dk_indices)`

If this works as is I'll make a separate PR to update PEP-007.
(cherry picked from commit 397f1b2)

Co-authored-by: Gregory P. Smith <[email protected]>
@miss-islington
Copy link
Contributor Author

@gpshead: Backport status check is done, and it's a success ✅ .

Copy link
Member

@gpshead gpshead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to merge https://github.com/python/cpython/pull/6549/files into this PR before it goes in.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Backport python@11659d0
into this change instead of leaving it a separate followup change.
Copy link
Member

@gpshead gpshead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even after tests pass, i'm going to let this sit for a while watching for any unexpected fallout on the master and 3.7 sides.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be poked with soft cushions!

@vstinner
Copy link
Member

@gpshead: What's the status of this backport?

@gpshead
Copy link
Member

gpshead commented Jul 2, 2018

Still desired but buried on my todo list.

@vstinner
Copy link
Member

vstinner commented Sep 4, 2018

@gpshead: ping again, 2 months later.

@zware zware changed the title [3.6] bpo-33312: Fix clang ubsan out of bounds warnings in dict. (GH-6537) bpo-33312: Fix clang ubsan out of bounds warnings in dict. (GH-6537) Sep 11, 2018
@zware zware changed the title bpo-33312: Fix clang ubsan out of bounds warnings in dict. (GH-6537) [3.6] bpo-33312: Fix clang ubsan out of bounds warnings in dict. (GH-6537) Sep 11, 2018
@bedevere-bot bedevere-bot added the type-bug An unexpected behavior, bug, or error label Sep 11, 2018
@miss-islington miss-islington merged commit ed74a25 into python:3.6 Sep 11, 2018
@miss-islington miss-islington deleted the backport-397f1b2-3.6 branch September 11, 2018 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants