Skip to content

[3.15] gh-159739: Handle overlapping buffers in struct.pack_into (GH-159985) - #160101

Merged
JelleZijlstra merged 1 commit into
python:3.15from
miss-islington:backport-31a7d99-3.15
Oct 22, 2026
Merged

JelleZijlstra merged 1 commit into
python:3.15from
miss-islington:backport-31a7d99-3.15

Conversation

@miss-islington

@miss-islington miss-islington commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

struct.pack_into() can use the same bytearray as both the destination and an s or p value. The copy then passes overlapping regions to memcpy, which is undefined in C and can produce platform-dependent results or a sanitizer abort. memmove makes the overlapping copy defined.
(cherry picked from commit 31a7d99)

Co-authored-by: Jelle Zijlstra jelle@openai.com

…onGH-159985)

`struct.pack_into()` can use the same bytearray as both the destination and an `s` or `p` value. The copy then passes overlapping regions to `memcpy`, which is undefined in C and can produce platform-dependent results or a sanitizer abort. `memmove` makes the overlapping copy defined.
(cherry picked from commit 31a7d99)

Co-authored-by: Jelle Zijlstra <jelle@openai.com>
@JelleZijlstra
JelleZijlstra merged commit 08fd98b into python:3.15 Oct 22, 2026
56 checks passed
@miss-islington
miss-islington deleted the backport-31a7d99-3.15 branch October 22, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants