Skip to content

Preserve binary path suffixes when patching prefixes - #37

Open
jezdez wants to merge 1 commit into
python:mainfrom
jezdez:fix-prefix-patching
Open

jezdez wants to merge 1 commit into
python:mainfrom
jezdez:fix-prefix-patching

Conversation

@jezdez

@jezdez jezdez commented Oct 22, 2026 •

Copy link
Copy Markdown

patch_path() currently pads a replacement prefix with NUL bytes before the rest of the path. Replacing PLACEHOLDER/lib/python3.16 therefore leaves C string readers seeing only the installation prefix, without /lib/python3.16.

Replace placeholders within each binary string, then pad its end. This preserves the path suffix and the original byte length, including when the same string contains multiple placeholders.

Skip .pyc and .pyo files because their marshalled strings are length-prefixed. Applying raw binary prefix replacement to them can insert NUL bytes into stored co_filename values.

@python-cla-bot

python-cla-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@itamaro

itamaro commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

this looks good to me.

it needs a ruff format pass, and so far we didn't have unittests for the tooling in this repo, so this would be the first one. since the intent is that all of this is temporary, I'm not sure if we want unittests, but I also don't object (I like tests), so I'd want @brettcannon's input on that.

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.

2 participants