Skip to content

Conversation

@neonene
Copy link
Contributor

@neoneneneonene commented May 3, 2024

Debug build on Windows (and CI: 7bbce38):

>_testembed_d test_repeated_init_exec "import datetime" --- Loop #1 --- --- Loop #2 --- Assertion failed: PyUnicode_CheckExact(ep_key), file C:\a\Objects\dictobject.c, line 1119 

At the Loop #2, the static types are carried over in the _datetime module, but their tp_dict no longer has valid keys, since all interned strings (keys) are freed after _PyUnicode_ClearInterned() in unicodeobject.c is invoked.

To check a key without a crash, the following strings need to be statically allocated:

  • The names in PyMemberDef array
  • The names in PyMethodDef array
  • The names in PyGetSetDef array
  • The key parameters of the PyDict_SetItemString(tp_dict, key, value) calls.

This patch includes the names that are already statically allocated (e.g. getset names).


@bedevere-appbedevere-appbot added the tests Tests in the Lib/test dir label May 3, 2024
@neoneneneonene changed the title datetime: Fix use-after-free on embedded CPythongh-113055: datetime: Fix use-after-free on embedded CPythonMay 3, 2024
@neoneneneonene marked this pull request as ready for review May 3, 2024 02:24
@neoneneneonene changed the title gh-113055: datetime: Fix use-after-free on embedded CPythongh-118608: datetime: Fix use-after-free on embedded CPythonMay 5, 2024
@neoneneneonene marked this pull request as draft May 5, 2024 20:04
@neoneneneonene closed this May 23, 2024
@neoneneneonene deleted the statickey branch May 23, 2024 14:21
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testsTests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@neonene